I know this comes up often on SO but I'm struggling to understand bits of it and hoping somebody can help.
I need to take the following:
http://www.xyz.com/news.room/showstory.php?storyid=123456
and create
http://www.xyz.com/newsroom/123456
http://www.xyz.com/news.room/
and create
http://www.xyz.com/newsroom/
http://www.xyz.com/files/pdf/uk/Wk51.pdf
and create
http://www.xyz.com/newsroom/convert/Wk51
in addition xyz.co.uk and xyz.org should also be rewritten to xyz.com and all should report back to the search engines as permanent redirects
I'm trying to do this in a htaccess file, that also has a standard CodeIgniter rewrite rule in it to remove the query strings.
Can anyone help me? I've tried several things but can't get anything that works for everything! Also i've spent five hours on this and am slowly pulling my hair out!
Any help, pointing in the right direction etc.. would be appreciated.
Cheers
#redirect any domain other than example.com, to example.com
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
RewriteRule ^newsroom/$ /news.room/
RewriteRule ^newsroom/([0-9]+)$ /news.room/showstory.php?storyid=$1
RewriteRule ^newsroom/convert/([^/]+)$ /files/pdf/uk/$1.pdf
Related
I am having some problems. I switched over from one e-commerce system to another a while back and this changed the url structure of some of the pages. I was fine with this and set up some rewrite rules. Somehow this has stopped working and I am not sure why.
I need to change
/product/{Category-Name}/{URL} to /{URL}
/ecategory/{Category-ID}/{URL} to /{URL}
/manu/{URL} to /{URL}
/news/{category-name}/{URL} to /blog/{URL}
I am using
RewriteRule ^/?(product|ecategory)/([^\/]+)/(.+?)\$ /$3 [R=301,L]
RewriteRule ^/?(manu)/(.+?)\$ /$2 [R=301,L]
RewriteRule ^/?(news)/([^\/]+)/(.+?)\$ /blog/$2/$3 [R=301,L]
RewriteRule ^/?(newscategory)/([^\/]+)/(.+?)\$ /blog/$3 [R=301,L]
RewriteRule ^/?([0-9]+)/(.+?)\$ /$2 [R=301,L]
Bu this is not working now and I don't have enough knowledge of htaccess redirects to work out what is wrong. I have been making changes and looking online but I feel like I am going in circles and this is very confusing.
Please, can anyone give me some advice?
I solved it by removing the / before the $. This was my mistake from when I think the URLs used to have .html at the end.
I have been battling for hours now and searched Google and StackOverflow, without a solution to my problem, hope you guys can help! :-)
I have a page with parameters as follows: profile?userid=123456789. I want it to rewrite to profile/123456789. This I have, but now everywhere on this page all links gets /profile/link. Is there any fixes to this? Thanks in advance, here comes my .htaccess code.
RewriteEngine on
RewriteCond %{REQUEST_URI} !/profile\.php
RewriteRule ^profile/([^/]*)$ /profile?userid=$1 [L,QSA]
try this, it works for me with many configurations
RewriteEngine On
RewriteRule ^profile/([^/]*)$ /profile?id=$1 [L]
if you want the ([^/]*) to be exclusively number, you'll need to use PHP to rewrite your urls
You can change your rule parameter order as below to make it work
RewriteEngine on
RewriteRule ^profile?userid=([^/]*)$ profile/$1 [L]
Hope this will help you :)
I know this question is asked by many users, also I gone through many questions to find the solutions as I am unable to understand the code used in htaccess file. So please kindly help me to solve this issue. I just want to convert a link like:
www.abc.com/project.php?proj-cat=some+project+name
to url like:
www.abc.com/project/some+project+name
OR to like:
www.abc.com/project/some-project-name/
I googled and found a website which creates a htaccess rule for you, using this site I got this:
RewriteEngine on
RewriteRule project/proj-cat/(.*)/ project.php?proj-cat=$1 [L]
but this doesn't redirect to the links above.
Please help me to find the solution for this and help me understand how it works. Thank You!
You can use this code in root .htaccess:
RewriteEngine On
RewriteBase /
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+project\.php\?proj-cat=([^\s&]+) [NC]
RewriteRule ^ project/%1? [R=302,L,NE]
# internal forward from pretty URL to actual one
RewriteRule ^project/([^/.]+)/?$ project.php?proj-cat=$1 [L,QSA,NC]
Reference: 1. Apache mod_rewrite Introduction
2. http://askapache.com
I have a brainteaser and need help from people smarter than me. I have a shared hosting account. I'd like to 301 forward the root URL (say, domain.org) to a new URL. I also want one folder (/blog/) to be left alone (not forwarded). I was able to find an example of this here, and I put together this potential scenario for doing that:
RewriteCond %{REQUEST_URI} !^/blog/
RewriteRule ^(.*)$ http://newdomain.org/$1 [L,R=301]
I believe that this should be OK, but here's the trick: I have add-on domains in this hosting, and if I use the above, I'm pretty sure that I will forward every one of them to newdomain.org, not just domain.org. I did some testing using more specific text strings in the first spot following RewriteRule, but I can't seem to get the syntax without blowing up my site and getting a 500.
Any ideas would be greatly appreciated!
Thanks, Dave
Try adding another condition:
RewriteCond %{HTTP_HOST} ^domain\.org$ [NC]
RewriteCond %{REQUEST_URI} !^/blog/
RewriteRule ^(.*)$ http://newdomain.org/$1 [L,R=301]
Where domain.org is the domain that you want everything to be redirected to newdomain.org, except /blog/.
Apologies if this is answered elsewhere. I had a search for this on here, but I'm quite confused so I'm not 100% what to search for in the first place.
I have a Wordpress site which is at exampledomain.com. I also own exampledomain.co.uk, and I have put in the .htaccess file the follow lines:
RewriteCond %{http_host} ^exampledomain.co.uk [nc]
RewriteRule ^(.*)$ http://exampledomain.com/$1 [r=301,nc]
These work fine in terms of changing exampledomain.co.uk to exampledomain.com, but the moment I add in something after the exampledomain.co.uk (i.e. exampledomain.co.uk/page1) the .htaccess file doesn't change it so it tries to load.
Is there something I can add to the .htaccess file which will sort this, so that, for example, if I were to type exampledomain.co.uk/page1 it would redirect to exampledomain.com/page1 ?
Thanks,
Charlie
P.S. Apologise for the weirdly parsed example links, but as a new user it won't let me include more than two hyperlinks.
Why not simply do
RedirectPermanent / http://exampledomain.com
in the co.uk's config instead? mod_rewrite is very handy, but for a simple domain redirector, it's major overkill.
comment followup:
I'd go for something like this:
RewriteCond %{HTTP_HOST} exampledomain.co.uk$ [NC]
RewriteRule (.*) http://exampledomain.com/$1 [R=301,L]