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/
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.
I am having issues trying to set up a correct htaccess file.
What I basically want to do is to implement clean URL and hide the .php extension except for one file.
What I currently have set up is the following:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^recruit(.*)$ recruit.php?id=/$1 [QSA,L]
#RewriteRule ^(?!recruit)(.*)$ $1.php [NC,L]
The first rule will take anything after 'recruit' and pass it as a get variable in the url
www.example.com/recruitHI --> www.example.com/recruit.php?id=HI
What the other rule needs to do is to append .php to anything else other than anything that starts with recruit.
www.example.com/index --> will look for index.php
www.example.com/contact --> will look for contact.php
www.example.com/recruit --> Needs to be ignored because of the first rule
When I have the 2 rules on and start apache, I get an error saying my configuration is wrong. They both work individually though.
You can use:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^recruit(.*)$ recruit.php?id=/$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]
2nd rule will add .php extension only for URIs that are not file or directories and that are already valid php files.
Try adding a condition to the second rule so that it won't blindly append a php to the end of the URI:
RewriteRule ^recruit(.*)$ recruit.php?id=/$1 [QSA,L]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
Specifying RewriteBase at the beginning. If everything is in the site root it would be
RewriteBase /
Otherwise all your Rules should begin with ^/
RewriteEngine On
RewriteBase /
RewriteRule ^recruit(.*)$ recruit.php?id=/$1 [QSA,L]
RewriteRule ^(.*)$ $1.php [NC,L]
Since your have the L The rules after recruit will only affect items that don't have it. But instead of having a script for every url possibility, you should look at using a single Front Controller.
RewriteEngine On
RewriteBase /
RewriteRule ^recruit(.*)$ recruit.php?id=/$1 [QSA,L]
RewriteRule ^(.*)$ index.php [NC,L]
Then you can use FallBack provider instead (newer in Apache)
RewriteEngine On
RewriteBase /
RewriteRule ^recruit(.*)$ recruit.php?id=/$1 [QSA,L]
FallbackResource /index.php
i need help redirecting this two links to one link:
Link #1: http://www.domain.com/index.php?til=d_news&id_new=1
Link #2: http://www.domain.com/new_folder/?til=d_news&id_new=1
need to redirect to:
http://www.domain.com/news/news.html
i tried using this code:
RewriteCond %{QUERY_STRING} ^til=d_news
RewriteRule ^(.*)$ http://%{HTTP_HOST}/news/news.html? [R=301,L]
but it only redirects the first link and not the second.
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 /
RewriteCond %{QUERY_STRING} ^til=d_news&id_new=1 [NC]
RewriteRule ^ /news/news.html? [R=301,L]
In the htaccess file in your document root, add:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^til=d_news&id_new=1
RewriteRule ^index.php$ /news/news.html? [L,R=301]
RewriteCond %{QUERY_STRING} ^til=d_news&id_new=1
RewriteRule ^new_folder/?$ /news/news.html? [L,R=301]
In your second link there is no destination page:
http://www.domain.com/new_folder/?til=d_news&id_new=1
should be something like:
http://www.domain.com/new_folder/page.php?til=d_news&id_new=1
I need something like this index.php?page=home to be /home
and
index.php?page=products&cat=chairs to be /products/chairs
What would be the mod_rewrite rule to achieve this?
Edited
I have other pages than home, so my full content of .htaccess file is now
RewriteEngine On
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
RewriteRule ^/products(:/([^/]+))? /index.php?page=products&cat=$1 [L]
But when I navigate to /products/chairs I get a "Object not found" error.
RewriteEngine on
RewriteRule ^/home/?$ /index.php?page=home [L]
RewriteRule ^/products(:/([^/]+))? /index.php?page=products&cat=$1 [L]
It rewrites both /home and /home/, both /products and /products/ (you didnt specify which was your intended behavior); beware that you will get an empty cat parameter in those cases.
EDIT: this is a tested .htaccess, with R=301 left on it to see rewriting result, with both .htaccess and index.php in same directory (webroot in my case):
RewriteEngine on
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [R=301,L]
RewriteRule ^products/([^/]+)?/? index.php?page=products&cat=$1 [R=301,L]
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 /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?page=(products)&cat=([^\s]+) [NC]
RewriteRule ^ %1/%2 [R=302,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?page=(home)\s [NC]
RewriteRule ^ %1 [R=302,L]
RewriteRule ^(products)/([^/]+)/?$ index.php?page=(products)&cat=$1 [L,QSA,NC]
RewriteRule ^(home)/?$ index.php?page=$1 [L,QSA,NC]
Change R=302 to R=301 after you verify it's working fine for you.
I am new to .htaccess and I have found a few articles and I've tried to make it work, but keep failing.
I have the following in my .htaccess file:-
<IfModule mod_ssl.c>
RewriteBase /mydomain.com/
</IfModule>
<IfModule !mod_ssl.c>
RewriteBase /
</IfModule>
RewriteEngine On
RewriteRule ^([^.]*)$ index.cgi/$1 [L]
However, I want to be able to go to mydomain.com/more-info, but this rule is making it mydomain.com/index.cgi/more-info
How can I make is so that "more-info" is exempt from this rule?
Thank you in advance.
So, Ulrich suggested the following...
#if not /more-info
RewriteCond %{REQUEST_URI} !^/more-info$ [NC]
RewriteRule ^([^.]*)$ index.cgi/$1 [L]
...but I still get '404 Not Found'. The more-info directory contains index.htm, and if I turn this RewriteEngine off, it works fine.
You can try this rule:
RewriteRule ^((?!more-info)[^.]*)$ index.cgi/$1 [L,NC]
Add a RewriteCond Directive before
RewriteRule ^([^.]*)$ index.cgi/$1 [L]
that exempts /more-info. Something like -
RewriteCond %{QUERY_STRING} != /more-info
You may find some examples here -> http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritecond
As below
#if not /more-info
RewriteCond %{REQUEST_URI} !^/more-info$ [NC]
RewriteRule ^([^.]*)$ index.cgi/$1 [L]