Trying to make a redirect from this url:
http://www.mywebsite.it/it/component/fss/?view=admin_support
to this url:
http://www.mywebsite.it/it/index.php/component/fss/?view=admin_support
I made a .htaccess file with this code:
RedirectMatch 301 ^/it/component/fss/?$ /it/index.php/component/fss/
All work if i click for the first time on the url. The url began /it/index.php/component but if i click into another link on the page ( like http://www.mywebsite.it/it/component/fss/?view=list ) i'm redirecting to the website home page.
But if i copy the address ( http://www.mywebsite.it/it/component/fss/?view=admin_support ) and i paste into another tab, the redirect work.
How i can solve this problem?
Thanks
Use mod_rewrite rules instead of RedirectMatch to match query string:
RewriteEngine On
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} \s/+it/(component/fss/?)\?view=[^&\s]+[&\s] [NC]
RewriteRule ^ /it/index.php/%1 [L,R=301]
Make sure to clear your browser cache before testing this change.
Try to with a private window:
If it works, you need just to clear your browser cache.
Related
I have a domain: soloENEGYBAR.ca which is properly redirecting to soloNUTRITION.ca as long as it's http://
This does NOT WORK for https:// and errors (I do not know why).
THE GOAL
Is there a way to make it so the sub folders for soloenergybar.com ALSO redirect to the home page for solonutrition.ca? As well as get this to work for http:// and https:// instead of just http://
For example, right now if I go to: soloenergybar.ca/en/home it redirects to solonutrition.ca/en/home which doesn't exist!
I would like to know if there's a way to force EVERY URL combo from soloenergybar.ca to go to the home page of solonutrition.ca vs adding the additional folder tree info /en/home/?
Thank you!
Current HTACCESS setting:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^132\.148\.131\.136
RewriteRule (.*) "https://www.solonutrition\.ca\/$1" [R=301,L]
You may use this rule in your site root .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} soloenergybar\.ca$ [NC]
RewriteRule ^ https://www.solonutrition.ca/? [R=301,L]
Make sure to clear your browser cache or test in a new browser to avoid old cache,
In .htaccess I want to redirect urls like this:
/products.php/a7-frames
/products.php/a6-frames
to this:
/picture-frames/a7-frames
/picture-frames/a6-frames
So need to substitute products.php with picture-frames.
After a lot of Googling I tried this:
RewriteBase /
RedirectMatch 301 (.*)\.php/?$ https://www.domainname.com/picture-frames$1
But it doesnt work, if I enter this url: /products.php/a7-frames the browser says there are too many redirects and goes to:
/picture-frames/index
It's substituting the products.php for picture-frames which is great, but I'm not sure why it adds "index" on the end rather than the /a7-frames part of the url? How can I fix this?
You can use these rules in your site root .htaccess:
RewriteEngine On
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+products\.php/([^\s?]+) [NC]
RewriteRule ^ /picture-frames/%1? [R=302,L,NE]
# internal forward from pretty URL to actual one
RewriteRule ^picture-frames/([^/]+)/?$ products.php/$1 [L,NC]
Make sure to clear your browser cache before testing this change.
i need to do some simple 301 redirects as i am creating a site fresh and using the current domain.
How ever the website URl's all start with '?'.
For example:
Redirect 301 /?q=news http://websitedomain/news/
This results in the home page being loaded with the url still the same.
Is there any way to get around this?
You need to use mod_rewrite to match against the query string :
RewriteEngine on
RewriteCond %{QUERY_STRING} ^q=([^&]+) [NC]
RewriteRule ^ http://example.com/%1? [NC,L,R]
On my website for SEO purpose the link to hotel.php?hotel_id=104 is changed to parkgrand.html
and changed htaccess to refer to the same script
code : RewriteRule ^parkgrand\.html$ /hotel.php?hotel_id=104
Till this it works fine. But I want if some user still accesses the old url i.e. hotel.php?hotel_id=104 then he should get automatically redirected to parkgrand.html and user agent should get a response 301
So, the code now becomes
RewriteCond %{REQUEST_URI} ^/hotel.php
RewriteCond %{QUERY_STRING} ^hotel_id=104
RewriteRule ^hotel.php /parkgrand.html [L,R=301]
RewriteRule ^parkgrand\.html$ /hotel.php?hotel_id=104
But this is causing a redirect loop and the intended page doesn't gets displayed to the user.
Can anyone tell me what should be the correct code for this.
Give this a try:
# Redirect /hotel.php?hotel_id=104 to /parkgrand.html
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+hotel\.php\?hotel_id=104[&\s] [NC]
RewriteRule ^ /parkgrand.html? [R=302,L]
Change from R=302 to R=301 once you confirm it is working to avoid caching.
Keep in mind you may have been cached from your previous attempts since you're using R=301, I will recommend you to test the above using a different browser to make sure its working in case your usual browser is cached.
Hi I tried various methods with modewriter in htaccess shown in other threads. I want to redirect my url from www.example.com/categories.php?category=1 to www.example.com/categories/science.
I would really appreciate an example too where I'm wrong. Thank You.
Assuming that it is just this one URL you want to redirect it would be like:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^category=1$ [NC]
RewriteRule ^categories.php$ www.example.com/categories/science/? [L,R=301]
This is in case you are using a .htaccess file, otherwise add a prepending slash:
RewriteRule ^/categories.php$ www.example.com/categories/science/? [L,R=301]
The querystring wil be discarded. Only put [R] if you want to show it to the user in the addressbar of the browser. Consider which status you want to serve, Google likes 301 if it's permanent.
Next you have to catch the incoming request with an index.php in the directory www.example.com/categories/science
good luck!