I try to make a redirect of a URL from my old site to my new site, but it does not work.
I think that the plus symbol is giving me problems.
RewriteRule ^nl/pageid/junair+compressor+onderhoud(|/)$ /nl/persluchttechniek/page/nieuwsberichten/compressor-onderhoud-junair [R=301,L]
Try this redirect rule in your root .htaccess of old site:
RewriteRule ^nl/pageid/junair[\s+]compressor[\s+]onderhoud/?$ /nl/persluchttechniek/page/nieuwsberichten/compressor-onderhoud-junair [NC,B<R=301,L]
Make sure this is your very first rule below RewriteEngine line. Also check there is no other .htaccess in your system.
The + is presumably a URL encoded space, try replacing it in the pattern with a \s.
RewriteRule ^nl/pageid/junair\scompressor\sonderhoud(|/)$ /nl/persluchttechniek/page/nieuwsberichten/compressor-onderhoud-junair [R=301,L]
Related
I've moved many url in my site from: /folder/page.php to: /folder/page/.
Now I want to redirect old url to new url, so I added in my .htaccess this rule:
RedirectMatch permanent /folder/(.*)\.php https://www.site.it/folder/$1/
But it doesn't work, this rule first redirect to /folder/page/ and then redirect again to /folder/page/index/
So I tried this:
RedirectMatch permanent /folder/(?!index)\.php https://www.site.it/folder/$1/
But it works like the above rule.
I tested also:
RedirectMatch permanent /folder/(?!index)(.*)\.php https://www.site.it/folder/$1/
same again.
I use .htaccess only in the root folder, here is the content before the new rule:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
These rules are required to redirect http traffic to https and are suggested by the web hosting service I use.
I also tested wrong RedirectMatch rule without any other.
How can I redirect all page except index.php?
Here is the list of url and the desired behavior:
/folder/ not match no action
/folder/index.php not match no action
/folder/subfolder/ not match no action
/folder/subfolder/index.php not match no action
/folder/anindex.php match redirect to /folder/anindex/
/folder/indexfile.php match redirect to /folder/indexfile/
/folder/anindexfile.php match redirect to /folder/anindexfile/
/folder/anotherfile.php match redirect to /folder/anotherfile/
Please do not suggest to use mod_rewrite because it is not the best practice as described here.
You may add a new rule below your existing rule:
RewriteCond %{THE_REQUEST} \s(/folder/[\w-]+)\.php[?\s] [NC]
RewriteRule ^ %1/ [L,R=301]
THE_REQUEST matches only original URI sent by client, it won't match modified REQUEST_URI.
I found this question: Match everything except for specified strings that help me to fix regex.
RedirectMatch permanent /folder/(?!.*(index))(.*)\.php https://www.site.it/folder/$2/
This rule match everything except index so redirect /folder/page.php only once to /folder/page/ but unfortunately, as #anubhava pointed out, this rule doesn't match any page name that contains index.
After further dig, I found this solution:
RedirectMatch permanent /folder/(?!index.php$|$)(([\w-]+)\.php$) https://www.site.it/folder/$2/
Anyway thanks to #anubhava that support me.
trying to redirect all trailing slash urls to non trailing slash on Cloudflare using a redirect page rule. I’m new to regex, can anyone help? Thanks
Tried: example.com/
To
*example.com/$2
But had no idea what I was doing
I believe you will need more than one rule to do this in a safe and sound way:
https://example.com/*/ to https://example.com/$1
https://example.com/*/?* to https://example.com/$1?$2
The first page rule is used to redirect sub-pages with a trailing slash; the second is used to redirect sub-pages with a query string. The same might be required for the base URL
https://example.com/ to https://example.com
https://example.com/?* to https://example.com?$1
However, you might be better off using a .htaccess file if your website is running on Apache like this:
RewriteEngine On
# Redirect non-directories to URL without trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [R=301,L]
If you do not care about directories simply remove the RewriteCond.
I managed to create such redirect URL with the following settings:
URL: https://example.com/*/
Destination URL: https://example.com/$1
Trying to do a simple URL rewrite with .htaccess but it does not seem to be working.
Want to access http://www.example.com/shop/index.php?route=information/information&information_id=11
using the URL http://www.example.com/MyGreatClub2013
This is what I have in my .htaccess which is stored at the www.example.com root level
RewriteEngine On
RewriteRule ^/MyGreatClub2013$ /shop/index.php?route=information/information&information_id=11 [NC,L]
Am I doing something stupidly wrong?
Remove leading slash:
RewriteEngine On
RewriteRule ^MyGreatClub2013/?$ /shop/index.php?route=information/information&information_id=11 [NC,L,QSA]
mod_rewrite rules when used in .htaccess don't match leading forward slash as .htaccess is per directory.
Here's a decent guide: http://www.javascriptkit.com/howto/htaccess.shtml
Hope it helps.
In my website,when it is clicked "www.anketurkiye.com/ekonomianket", I want to my site to redirect to www.anketurkiye.com/ekonomibuton.php page. I have written the following script.However it doesn't run correctly. How can I solve this problem.
RewriteEngine on
RewriteRule ^/ekonomianket$ ekonomibuton.php [NC,L]
Replace that RewriteRule line with this:
RewriteRule ^ekonomianket/?$ ekonomibuton.php [NC,L]
In your .htaccess leading slash is stripped off so you need to match without leading slash.
I have the following Rules setup in my .htaccess file
RewriteRule ^detail.php / [R=301,NC,L]
RewriteRule ^tempate.php / [R=301,NC,L]
What these do is perform a 301 redirect when detail.php and template.php is called, although this works this is not working when I enter mydomain.co.za/detail.php?product_id=2432&category=700 then it redirects the website to mydomain.co.za/?product_id=2432&category=700
I need any url where the filename is detail.php or template.php with any amount of parameters in the query string to redirect to the home page
I tried RewriteRule ^detail.php?(.*) / [R=301,NC,L] and this also not working. Any help or guide will be appreciated.
Replace your 2 RewriteRule lines with this line:
RewriteRule ^(?:detail|template)\.php$ /? [R=301,NC,L]
Note that question mark after /, that is a special mod_rewrite syntax to strip out any existing query string from original URI.
Also remember that RewriteRule only matches URI without query string therefore your attempt of ^detail.php?(.*) / [R=301,NC,L] won't work as you expected.