mod_rewrite - Change Folder to Filename [closed] - regex

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Improve this question
I'm searching for a RewriteRule or Condition to make this happen:
www.example.com/a/ to a.php
www.example.com/a/b/ to a,b.php
www.example.com/a/b/c/ to a,b,c.php
...
I had this Rules:
RewriteRule ^(.+)/(.+)/(.+)/$ ./$1,$2,$3.php [L]
RewriteRule ^(.+)/(.+)/$ ./$1,$2.php [L]
RewriteRule ^(.+)/$ ./$1.php [L]
That worked for a,b and a,b,c:
www.example.com/products/room/ to products,room.php
www.example.com/products/room/chair/ to products,room,chair.php
but not for a:
www.example.com/products/ to products.php
Can anyone help me out?
EDIT:
I figured out that this is a problem with the synology diskstation apache configuration.
I checked my code, and the code of anubhava on another server and it worked fine.

Very strange filenames I must say that.
Anyway try this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
## If the request is for a valid directory
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([^/]+)/?$ /$1.php [L]
RewriteRule ^([^/]+)/([^/]+)/?$ /$1,$2.php [L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /$1,$2,$3.php [L]

Related

Apache rewrite rule with query [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
i need to rewrite mydomain.com/something/?p=value to mydomain.com/something/?page=value
I tried:
RewriteEngine On
RewriteCond %{QUERY_STRING} p=(.*)
RewriteRule ^(.*)/p=$ $1?page=%{QUERY_STRING} [L,QSA]
but don't wok, can help me?
Could you please try following, I haven't tested it yet, written in mobile will test it in sometime, should work I believe.
RewriteEngine On
RewriteCond %{QUERY_STRING} ^p=(.*)$
RewriteRule ^(.*)$ /$1?page=%1 [L,NE]

Replace string in URL using apache [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I am new to apache web server.
I have a URL like :-
www.example.com/example1/{ dynamic string }/p123465/content
I want to convert it into:
www.example.com/example1/{ dynamic string }/pid/content
here dynamic string is different every time.
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule ^(example1/[^/]+)/p123465/(content)/?$ /$1/pid/$1 [L,NC,R]
Or if you already have /example1/.htaccess then use
RewriteEngine On
RewriteBase /example1/
RewriteRule ^([^/]+)/p123465/(content)/?$ $1/pid/$1 [L,NC,R]

I want to change my url (htaccess) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to change my url (htaccess)
from :
www.website.com/page.php?id=128
to :
www.website.com/?a=128
and
www.website.com/images.php?id=128
to :
www.website.com/?i=128
thank you
put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)i=([^&]+)
RewriteRule ^$ /images.php?id=%1 [L]
RewriteCond %{QUERY_STRING} (^|&)a=([^&]+)
RewriteRule ^$ /page.php?id=%1 [L]

Search engine friend search string using htaccess [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Is it possible to alter my search result url say from this:
/search.php?query=Currys
To something more search engine friendly and also add to it so that it becomes something like this:
/search-results-for-Currys-Voucher-Codes
By using htaccess?
Thanks.
You can probably do something like this by placing this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+search\.php\?query=([^\s&]+) [NC]
RewriteRule ^ /search-results-for-%1? [R=301,L,NE]
# internal forward from pretty URL to actual one
RewriteRule ^search-results-for-(.+?)/?$ /search.php?query=$1 [L,QSA,NC,NE]
Then inside search.php get your parameters as $_GET['query']

301 htaccess redirect for a pattern [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I want to 301 redirect to all my URLs who have a specific pattern.
Old URLs are like
http://www.example.in/1231/ask-meaning-in-hindi
http://www.example.in/1233/blow-meaning-in-hindi
http://www.example.in/1235/beyond-meaning-in-hindi
I want to redirect them to a pattern like this:
http://www.example.in/1231/ask
http://www.example.in/1233/blow
http://www.example.in/1235/beyond
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^([0-9]+/[^-]+)-.+$ /$1 [L,R=301]