I have url rewrite problem.
my file is present in
www.example.com/test2/test.php
i want to write url as
www.example.com/test.html
my code in .htaccess file
RewriteEngine On<br />
RewriteRule ^([a-zA-Z0-9-/]+).html$ test2.php?id=$1
RewriteRule ^([a-zA-Z0-9-/]+).html/$ test2.php?id=$1
rewriterule ^([a-za-z0-9-/]+).html$ test2.php?id=$1
rewriterule ^([a-za-z0-9-/]+).html/$ test2.php?id=$1
.htaccess file is in test2 directory.
please help me.
This may work for you.
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\.html$ test2.php?id=$1 [L]
Related
I have site e.g. 123.123.123.123/subdirectory/ and I would like to rewrite
123.123.123.123/subdirectory/page/123
to
123.123.123.123/subdirectory/page.php?id=123.
I've created .htaccess file:
RewriteEngine On
RewriteBase /subdirectory
RewriteRule ^page/(.*)$ page.php?id=$1 [NC,L,QSA]
but it doesn't work (rewriting in on).
Use this rule and it will work.
RewriteRule ^123\.123\.123\.123/subdirectory/page/123$ /123.123.123.123/subdirectory/page.php?id=123&%{QUERY_STRING}
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 actually thought there should already be a thread about this but i wasn't able to find one.
let's say i have a website with this structure:
/index.php
/.htaccess
/template
/template/css
/template/css/foo.css
I'm redirecting everything to index.php with .htaccess
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)$ index.php?0=$1 [QSA,L]
Now I've got a problem with the css. that i could fix by placing another .htaccess in /template with this
RewriteEngine off
Options -Indexes
And then access the css file with http://example.com/template/css/foo.css but actually i would prefere to have just http://example.com/css/foo.css
So i tried to put in /.htaccess the following code (that didn't worked). What did i do wrong?
RewriteEngine on
RewriteBase /
RewriteRule ^/css/(.*) www/css/$1 [L]
RewriteRule ^/js/(.*) www/js/$1 [L]
RewriteRule ^(.*)$ index.php?0=$1 [QSA,L]
note I don't have any .htaccess in /template!
You should remove the htaccess file in the css folder. You just need to exclude rewrites to the template directory. You can do it all in a single file:
RewriteEngine on
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}/template/%{REQUEST_URI} -f
RewriteRule ^(.*)$ /template/$1 [L]
RewriteCond ${REQUEST_URI} ^/template/
RewriteRule ^(.*)$ index.php?0=$1 [QSA,L]
The first rule handles requests for the css directory, and the second rule is the one you had that routes to index.php except if the request is for template.
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 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]