I need to remove text from the end of my URL. The URL will look somthing like the following:
www.test.co.za/news/cat/index-mobile.html
www.test.co.za/page-name/index-mobile.html
I need to remove the index-mobile.html from the URL.
Thank you in advance.
You can use this rule in your site root .htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+(.*)/index-mobile\.html\s [NC]
RewriteRule ^ /%1? [R=301,L,NE]
# rest of your rules ho here
Related
I would like the URL:
https://example.com/en/category/post+name_tour123456
To point to:
https://example.com/en/category/post+name+123456
I want to delete _tour
Can I do it with .htaccess?
I have created a regex to match all of these links:
((http[s]?):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([^_]+(?=_)*)(\W?_tour?)([0-9]*)
Thank you
So you can just match on the request. Try this rule and see how it works.
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\ /en/category/(.+)\+(.+)\+_tour(.*) [NC]
RewriteRule ^ /en/category/%1+%2+%3 [R=301,L]
Need to use .htaccess to redirect all urls that have blog-entry in path like this:
http://example.com/blog/blog-entry/blog-title
to this:
http://example.com/blog/blog-title
Tried this per another stack answer, but no luck:
RewriteRule ^blog-entry/(.*)$ $1 [L,R=301,QSA]
Please advise.
Change your rule with this rule:
RewriteCond %{THE_REQUEST} \s/+(.*)/blog-entry/(\S*) [NC]
RewriteRule ^ /%1/%2 [R=301,NE,L]
Since we're using THE_REQUEST here, this rule will work from site root or /blog/ directory.
I have a url below:
http://www.mysite.com/mypage.php?PropertyBuyRent=rent&Developer=&Resort=&City=&State=&Country=&Price=
if PropertyBuyRent=rent and all other variables are empty then url should be like:
http://www.mysite.com/mypage.php/TimeshareForRent/All
how can i write htaccess for this?
You can use this rule:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(testing/mypage\.php)\?PropertyBuyRent=rent&Developer=&Resort=&City=&State=&Country=&Price= [NC]
RewriteRule ^ /%1/TimeshareForRent/All? [R=301,L]
RewriteRule ^(testing/mypage.php)/TimeshareForRent/All/?$ /$1?PropertyBuyRent=rent&Developer=&Resort=&City=&State=&Country=&Price= [L,NC,QSA]
Reference: Apache mod_rewrite Introduction
You can use this line and make edits in php file as follows
RewriteRule ^mypage.php/TimeshareForRent/All/?$ mypage.php?PropertyBuyRent=rent&Developer=&Resort=&City=&State=&Country=&Price= [L,NC,QSA]
You can tell your php file to redirect to "mypage.php/TimeshareForRent/All" when your condition matched, because with above rule, it will mask the url of variables with the one without variable
I have a condition for url redirect like,
www.domain.com/something/anotherthing/index.php
i need the above url to redirect to
www.domain.com/something/anotherthing/
If i go to
www.domain.com/index.php/something/anotherthing
i want to redirect to
www.domain.com/something/anotherthing
i have a redirect htaccess rule for this
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index.php$1 [NC]
RewriteRule ^ /%1$1 [R=301,L]
But this works for the first condition but in the later it redirect me to the root page. Can anyone please help in this redirection.
Thanks in Advance.
Try something like this:
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index.php/?([^\ \?]*) [NC]
RewriteRule ^ %1/%2 [R=301,L]
That should handle any location of /index.php.
I have a dynamic query string that I need to pass via an .htaccess redirect. For example:
I need to redirect this URL: http://mysite.com/page1?action=signup&var2=dynamicVar
To this: http://mysite.com?action=signup&var2=dynamicVar
I know this is pretty simple, but I'm really not sure what type of rule/syntax would work for this.
Any help is greatly appreciated!
If you already have .htaccess then simply add this line:
RewriteRule ^page1/?$ page2 [L,R,QSA,NC]
Update: Based on your comments:
RewriteCond %{QUERY_STRING} (^|&)action=signup(&|$) [NC]
RewriteRule ^page1/?$ / [L,R,QSA,NC]
RewriteRule ^page1(.*)$ /page2$1 [L,R=301]
Input
http://mysite.com/page1?action=signup&var2=dynamicVar
this is the rewrite rule
RewriteRule ^page1?(.*)$ /?$1 [L,R=301]
redirect to
http://mysite.com/?action=signup&var2=dynamicVar
this will redirect all request o page1 with get parameters to http://mysite.com
Use %{REQUEST_URI}
fi.:
RewriteCond %{HTTP_HOST} ^website\.(.+)$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
rewrites anything that starts with "website" to "www.website..." including the querystring (by use of %{REQUEST_URI})