I need some help with .htaccess RewriteRules. Using index.php to parse parameters and render a needed page.
I have a link domain.com?ac=221&co=100. It needs to be accessed by url domain.com/221/100
I've already made a RewriteRule for ?ac -
RewriteRule ^([^/d]+)/?$ index.php?ac=$1 [QSA]
How can I add a support for second argument?
Possible url variants:
domain.com
domain.com?ac=221
domain.com?ac=221&co=100
Options -MultiViews
RewriteEngine On
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?ac=$1&co=$2 [NC,QSA,L]
RewriteRule ^([a-zA-Z0-9]+)$ index.php?ac=$1 [NC,QSA,L]
Related
I have no experience working with htaccess, so i have this url: index.php?id=1163&sub=hp
i have managed to convert the first portion into a friendly url with htaccess:
www.mytesturl.com/index.php?id=1163 into www.mytesturl.com/computers/
however i need to convert the whole url (two parameters) for example:
www.mytesturl.com/index.php?id=1163&sub=hp into www.mytesturl.com/computers/hp/
here is my htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?perf=$1
Options -Indexes
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.mytesturl.com
RewriteRule (.*) http://www.mytesturl.com/$1 [R=301,L]
</IfModule>
can someone please point me into the right direction? the second instruction should be on the same line or its necesary to add another rule or directive
similar to: RewriteRule (.*) http://www.mytesturl.com/$1 [R=301,L]
You can possibly use:
RewriteEngine On
RewriteRule ^([\w-]+)/?$ index.php?perf=$1 [L,QSA]
RewriteRule ^([\w-]+)/([\w-]+)/?$ index.php?perf=$1&sub=$2 [L,QSA]
But remember your rules are using ?perf=... as first parameter not ?id=... as your question says.
This is my first post so excuse me if something it's wrong with my way of asking for help. I've been reading other posts related to my problem but none solved it.
My path:
http://example.com/m/page1
http://example.com/m/page2
...
And so on.
I want to change the /m/pageX to /m/#pageX without hardcoding the URL and without using any additional php scripts.
At the first sight, I've accomplished this task by writing the following .htaccess configuration file:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^[dm]/(.+)$ /m/#$1 [R=302,NE,L,NC]
## hide .php extension
RewriteCond %{THE_REQUEST} \s/+common_([^.]+)\.php[\s?] [NC]
RewriteRule ^ %1 [R=302,L,NE]
## To internally forward
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/common_$1.php -f
RewriteRule ^(.+?)/?$ common_$1.php [L]
Is my code the best solution or there is other way to approach my task ?
How can I redirect the /m/pageX to /d/#pageX ?
Thank you
The # sign is not supported in URLs.
This will rewrite /m/pageX to /d/pageX:
RewriteEngine On
RewriteRule ^m/(.*) /d/$1 [L,R=301]
This will rewrite /m/pageX to /d/pageX#example, but #example is fix:
RewriteEngine On
RewriteRule ^m/(.*) /d/$1#example [NE,L,R=301]
[NE] is necessary to keep the hash (#) sign.
This will rewrite /m/pageX to /d/#pageX:
RewriteEngine On
RewriteRule ^m/(.*) /d/#$1 [NE,L,R=301]
Try these rules in your root .htaccess (a level above /m/ and /d/):
RewriteEngine On
RewriteRule ^d/(.+)$ /m/#$1 [NE,NC,L,R=302]
RewriteRule ^(.+)$ /#$1 [NE,L,R=302]
Make sure to remove any /d/.htaccess file.
If for some reason you want to do it from /d/.htaccess then use this rule in /d/.htaccess file:
RewriteEngine On
RewriteRule ^(.+)$ /m/#$1 [NE,NC,L,R=302]
I cannot get my rewrite map to work. I have read a lot of pages on this and yet can't figure out how.
I have the following in my httpd.conf and took an apache restart
RewriteMap ErrorMap txt:/usr/local/apache/conf/userdata/std/1/techencl/site.com/vb2xf.map
The rewrite map has the following entry (edited after the tip in the first reply)
corner/lock-unlock-140859.html http://www.site.com/com/ts/lock-unlock.70898/
The .htaccess in the root directory has the following entry
RewriteCond ${ErrorMap:$1|NOT_FOUND} !NOT_FOUND
RewriteRule ^(.*)$ ${ErrorMap:$1|$1} [R=301]
Edit: Just posting my current .htaccess file contents for reference
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule [^/]+/.+-([\d]+)/p([\d]+)/ showthread.php?t=$1&page=$2 [NC,L]
RewriteRule [^/]+/.+-([\d]+)/ showthread.php?t=$1 [NC,L]
Options +FollowSymlinks
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
RewriteCond ${ErrorMap:$1|NOT_FOUND} !NOT_FOUND
RewriteRule ^(.*)$ ${ErrorMap:$1|$1} [R=301]
</IfModule>
When you call the map:
${ErrorMap:$1
The $1 is never going to have http://www.site.com/ in it. It will only have this part:
corner/lock-unlock-140859.html
That means in your map, you need to make it look like this:
corner/lock-unlock-140859.html http://www.site.com/com/ts/lock-unlock.70898/
i have following url structure
http://www.mydomain.com/vpn-providers.php?st=30&page=2
and .httaccess rules for making seo are
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301]
RewriteRule ^vpn-providers([^-]*)-([^-]*)\.html$ /vpn-providers.php?st=$1&page=$2 [L]
the above code is used in pagination urls.
i want to make URLs a bit SEO friendly...My required out put is
http://www.mydomain.com/vpn-providers-2.html (2 is the page number
here ie page=2)
Can someobdy tell me where i am doing error? How can i modify my htaccess rules?
I have a php site. For all of the page links I use foo.htm, and internally rewrite this to foo.php with .htaccess:
RewriteRule ^(.*)\.htm$ $1.php [NC,L]
This works great - however, it still allows you to use the foo.php url. I would like to 301 redirect foo.php to foo.htm to prevent any old foo.php search engine results from hanging around and rewrite the foo.htm url internally to foo.php
I can't figure out how to do this without creating a loop.
Put this code in your .htaccess file:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{THE_REQUEST} ^GET\s(.+)\.php [NC]
RewriteRule ^ %1.htm [R=301,L]
RewriteRule ^(.*)\.htm$ /$1.php [L,NC]
RewriteRule ^(.*)\.htm$ $1.php [NC,L]
RewriteRule ^(.*)\.php$ $1.htm [NC,R]
the option L stops the rewriting engine, preventing a loop.