Hi I am having an issue with .htaccess on 301 redirects.
Everything looks fine, on 90% of the urls but not for any of the individual blog post redirects.
here is the code where they do not redirect:
RewriteRule ^blog-article.php?id=38 blog-post/xxxx-xxxxxx-xx-x-xxxxxxx/9/ [L,NC,R=301]
RewriteRule ^blog-article.php?id=34 blog-post/xxxxxxx/4/ [L,NC,R=301]
But the all of the other 301 rewrites work, and they look like this:
RewriteRule ^old-url-portfolio/(.*)$ page/new-url-portfolio/$1 [L,NC,R=301]
RewriteRule ^Portfolio/Detail/(.*)$ portfolio/$1 [L,NC,R=301]
RewriteRule ^old-url/7/ page/new-url/ [L,NC,R=301]
RewriteRule ^contact-us-old/ page/contact-us-new/ [L,NC,R=301]
RewriteRule ^blog.php page/blog/ [L,NC,R=301]
I can not find why they are not working, its not because the ones that are not working are individual files because the blog.php file is being sent to the new page.
Any ideas would be appreciated :)
You can not match against querystring in RewriteRule's pattern. To redirect blog-article.php?id=123 to diffrent location , you need to match against %{QUERY_STRING} using RewriteCond directive.
RewriteCond %{QUERY_STRING} ^id=123$
RewriteRule ^blog-article.php$ /location/? [L,R]
Note :The traling ? at the end of the destination path is important as it discards the old querystring.
Found a work around, it seams the issue is the ?id=number so I simply did this:
RewriteCond %{QUERY_STRING} ^id=38$
RewriteRule ^blog-article\.php$ http://www.xxxxxxx.co.uk/blog-post/xxxx-xxxxxx-xxxx/9/ [R=301,L]
Related
This is my page url example.com/platform/bidProject.php?pID=JCVGK&name=Proof%20Reading%20Blogs
These rules helped me to Rewrite this as example.com/platform/project-bids/JCVGK/Proof-Reading-Blogs/
RewriteRule ^platform/project-bids/(.*)/(.*)/?$ /platform/bidProject.php?pID=$1&name=$2 [L,NC]
RewriteCond %{THE_REQUEST} \s/platform/bidProject.php?pID=$1&name=$2
RewriteRule ^platform/bidProject.php?pID=$1&name=$2 /platform/project-bids/(.*)/(.*)/ [NC,R=301,L]
but the issue is if I visit to the page example.com/platform/bidProject.php?pID=JCVGK&name=Proof%20Reading%20Blogs the url stays same. I want this to be redirected to example.com/platform/project-bids/JCVGK/Proof-Reading-Blogs/
So I tired this:
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^(\S+)$ /$1 [NE,R=302,L]
RewriteRule ^([^/]+)/([^/]+)/?$ /platform/bidProject.php?pID=$1&v=$2 [L,QSA]
Seems I am doing something wrong with this because it makes no any affect on this.
I found a solution to redirect using JavaScript but I like to have .htaccess solution because JavaScript can be disable and can be seen in the source code. The basic intention for doing this fails here.
How can I achieve this using .htaccess
My htaccess path is example.com/.htacsess
You can use these Rules
RewriteEngine on
#redirects /platform/bidProject.php. php?pid=val1&name=val2 to /platform/project-bids/val1/val2/
#redirects the old url to the new one
RewriteCond %{THE_REQUEST} \s/platform/bidProject.php\?pID=([^&]+)&name=([^&\s]+) [NC]
RewriteRule ^ /platform/project-bids/%1/%2/? [NC,R,L]
# rewrites or internally maps the new url to the old one
RewriteRule ^platform/project-bids/(.*)/(.*)/?$ /platform/bidProject.php?pID=$1&name=$2 [L,NC]
Or
RewriteEngine on
RewriteCond %{ENV_REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^pid=([^&]+)&name=([^&]+)$ [NC]
RewriteRule ^platform/bidProject.php$ /platform/project-bids/%1/%2/? [NC,R,L]
RewriteRule ^platform/project-bids/(.*)/(.*)/?$ /platform/bidProject.php?pID=$1&name=$2 [L,NC]
Change R to R=301 (permanent redirect) when you are sure the rule is working ok.
I have links to user profiles like:
https://example.com/chat/index.php?action=user&member=547
https://example.com/chat/index.php?action=user&member=11540
etc.
My goal is to mod-rewrite such URLs so that they look nicer, ie. they should look like:
https://example.com/chat/member-547/
https://example.com/chat/member-11540/
etc.
And URLs without a trailing slash, ie.
https://example.com/chat/member-547
should be 301-forwarded to one with slash, ie.
https://example.com/chat/member-547/
So in .htaccess I tried this, but only the first line seems to work and it's not complete:
RewriteRule ^chat/member-([0-9]+)/$ ./index.php?action=user&member=$1
RewriteRule ^chat/member-([0-9]+)$ /member-$1/ [R=301,L]
TO SUMMARIZE:
When someone enters URL like:
https://example.com/chat/index.php?action=user&member=547
it should be 301-redirected to:
https://example.com/chat/member-547/
When someone enters:
https://example.com/chat/member-547
it should also be 301-redirected to:
https://example.com/chat/member-547/
I hope there's an efficient way to do it right.
Starkeen's answer is correct, and will work. I'll just suggest an alternative, which acts on the raw request variable itself:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET\ /chat/index\.php\?action=user&(member)=(\d+) [NC]
RewriteRule ^chat/index\.php$ /chat/%1-%2/? [R=301,L]
RewriteRule ^chat/member-([0-9]+)$ /member-$1/ [R=301,L]
RewriteRule ^chat/(member)-(\d+)/$ /chat/index.php?action=user&$1=$2 [L]
You can use the following rule :
RewriteEngine on
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteCond %{QUERY_STRING} ^action=([^&]+)&member=(.+)$
RewriteRule /chat/index\.php$ /chat/member-%2/? [L,R=301]
RewriteRule ^chat/member-(.+)/?$ /chat/index.php?action=user&member=$1 [L]
i want to redirect specific urls from
http://www.domain.com/com/page.asp?id=99
to
https://www.domain.com/de/directory/
and all urls from
http://www.domain.com/com/page.asp
to
https://www.domain.com/de/
ive tried some redirects but i cant get it done right.
Please help me!
RewriteCond %{query_string} id=5
RewriteRule (.*) https://www.domain.com/de/directory/? [R=301,L]
this works, but the biggest problem is all urls in the cms https://www.domain.com/cms are redirected too if they contain an id
Try:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=99$
RewriteRule ^page\.asp$ /de/directory/ [L,R]
RewriteRule ^page\.asp$ /de/ [L,R]
I'd like to redirect http://domain.com/videos/?src=category1&video=video1
To http://domain.com/videos/watch?v=1
The obvious, just using a Redirect 301 /old /new doesn't work here. Here's my starting point and I can't seem to get this to redirect properly. This .htaccess file lives in the videos directory.
RewriteCond %{QUERY_STRING} ^src=category1&video=video1$ [NC]
RewriteRule /videos/watch\?v=1 [L,R=301]
Try:
RewriteCond %{QUERY_STRING} ^src=category1&video=video1$ [NC]
RewriteRule ^$ /videos/watch?v=1 [L,R=301]
You were missing the rewrite rule's regex pattern.
As the title says, I need a quite complex url rewrite mechanism for a web-app as .htaccess rule.
I've searched quite a lot now and tried hundred of different rewrite rules.
So, basically this is what I need:
User goes to: http://www.site.com/product.php?id=12
Server should redirect to: http://site.com/product/12
Once thing to mention:
not all pages do append id's.
So I also have: http://www.site.com/some/page.php
which then should redirect to: http://site.com/some/page
or from http://site.com/anotherone.php to http://site.com/anotherone
You help is much appreciated and thank you a lot in advance for you help!
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)\.php$ http://%1/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)\.php\?id=([0-9]+)$ http://%1/$1/$2 [R=301,L]
I supose that you, previously have this mod_rewrite rule active:
Users goes to http://site.com/product/12 and in the browser is showed this URL, and internaly, and only internaly, server serve http://www.site.com/product.php?id=12
Put the first RewriteCond and Rule this:
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule ^(\w+)\.php\?id=(\d*)$ /$1/$2 [R=301]
And add another to remove the .php when ends with .php
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule ^(\w+)\.php$ /$1 [R=301]