I want to rewrite my url with htaccess, when URL contains a certain string.
Example:
My url : example.com/information
When "information" is in my url, I want to rewrite to my information.php file.
Hope anyone can help me out.
Try this:
RewriteCond %{REQUEST_URI} !/information\.php$
RewriteRule information information.php [L]
This rule will rewrite any request that contains “information” in the URL path to information.php in the same directory.
Source
Related
I am trying to mask the following url with any page number using htaccess.
https://sampledomain.com/?page=2
to
https://sampledomain.com/page/2
So if we call https://sampledomain.com/page/2 url in the website, internally path should always be calling https://sampledomain.com/?page=2 url
Please suggest me the correct htaccess rule.
In htaccess in your document root, use the following rule :
RewriteEngine on
RewriteRule ^page/([0-9]+)/?$ /?page=$1 [QSA,L]
I wanna change "announcements.php" to "blog.php" in the url. Individual article's are identified by id=x, such as"annoucements.php?id=1", which I will need it to say "blog.php?id=1".
I tried:
RewriteRule ^announcements.php ./blog.php
Try with:
RewriteEngine on
RewriteRule ^announcements\.php /blog.php [NC,L]
If you change the file name in the url, you do a redirection, not a rewrite.
I'd like to rewrite part of URLS like:
http://www.myweb.com/cat1/subcat2/how-to-do-this
to
http://www.myweb.com/cat2/subcat2/how-to-do-this
there are many urls in which the end part(how-to-do-this) changes
I have tried this:
RewriteRule ^cat1/subcat1/(.*) /cat/subcat2 [R=301,L,NC]
but this doesn't works.
Please help.
R=301 is used for external redirection, if you want to rewrite the request , you can use the following :
RewriteRule ^cat1/subcat2/(.*) /cat2/subcat2/$1 [L,NC]
This will internally redirect (without changing the url in browser)
cat1/subcat2/foo
to
cat2/subcat2/foo
Need help to strip out this string from url
index....</div></images/myblog_images/978
Incorrect URL
http://www.abc.com/index....%3C/div%3E%3C/images/myblog_images/978/index.php?option=com_news&view=detail&n_id=20&Itemid=4
Correct URL
http://www.abc.com/index.php?option=com_news&view=detail&n_id=20&Itemid=4
Many thanks
Edit
Hello Anubhav
While applying the htaccess condition - the url is been changed to
http://www.abc.com/home/truecar7/public_html/index.php?option=com_news&view=detail&n_id=20&Itemid=4
You can try this code:
RewriteRule ^.+?(index\.php)$ /$1 [L,NC,R=301]
I'm looking to rewrite old PHP pages to new locations, however the previous system used URLs structured as follows:
/old-page.php?page=Our%20Services
I've tried the following:
Redirect 301 /old-page.php?page=Our%20Services http://www.newdomain.co.uk/our-services/
Can someone help explain to me why the rewrite rule ignores everything after the question mark please?
You can use Redirect for simple cases only. If you want to check the query string, you must use mod_rewrite and RewriteCond
RewriteEngine on
RewriteCond %{QUERY_STRING} page=Our%20Services
RewriteRule ^old-page.php$ http://www.newdomain.co.uk/our-services/ [R,L]
This checks, if the query string contains page=Our%20Services and the URL path is old-page.php. It then redirects the client to the new URL http://www.newdomain.co.uk/our-services/.