Forum Moderators: phranque

Message Too Old, No Replies

Mod Rewrite to remove unecessary folders

Mod Rewrite to remove unecessary folders

         

Armyboy1066

3:23 pm on Nov 21, 2010 (gmt 0)

10+ Year Member



Hi,

I have been wracking my brains trying to find a solution (and easy explanation with examples) of how to rewrite the following URLS:

http://www.example.com/component/content/66-msm-blog-jan-2009?start=20

1. to remove the bold folders;

and

2. to rewrite to the home page http://www.example.com

Any help would be most appreciated.

Regards

bagizoli

4:46 pm on Nov 21, 2010 (gmt 0)

10+ Year Member



Hi,

1. To remove bold folders
RewriteRule ^component/content/([a-zA-Z0-9-]+)$ /$1 [R=301]

2. To rewrite to home page
RewriteRule ^component/content/([a-zA-Z0-9-]+)$ / [R=301]

Thanks,
Zoli

g1smd

4:58 pm on Nov 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Those are not rewrites. Those are external redirects.

bagizoli

6:39 pm on Nov 21, 2010 (gmt 0)

10+ Year Member



Leave the [R=301] from the end of each line and they will be rewrites.
Thanks

Armyboy1066

7:02 pm on Nov 21, 2010 (gmt 0)

10+ Year Member



Hi thanks for the swift response, however I am still getting a 404 error. The URL is not being rewritten in either case 1 or 2 above.

I have a number of URLs to rewrite in this way so the end of the URL needs to be anything, not just as in this case:

66-msm-blog-jan-2009?start=20

Is that what the Rules you have set above are intended to do.

bagizoli

9:57 am on Nov 22, 2010 (gmt 0)

10+ Year Member



This rewrite

RewriteRule ^component/content/([a-zA-Z0-9-]+)$ /$1

tells Apache to serve /66-msm-blog-jan-2009?start=20 when the /component/content/66-msm-blog-jan-2009?start=20 webaddress is requested. At the moment I'm a bit unsure that you want to make it work this way, and not the opposite. I might misunderstand. :-)

Armyboy1066

10:50 am on Nov 22, 2010 (gmt 0)

10+ Year Member



I will try to explain this better:

Currently I have a URL being served which causes a 404 error because the CMS software i am using has removed the "component/content/"

So I have this URL served:

http://www.example.com/component/content/66-msm-blog-jan-2009?start=20

and I want to have 2 rewrite rules

1) to remove the component/content/

So the rewritten URL would be http://www.example.com/66-msm-blog-jan-2009?start=20

AND

2) to drop the whole "component/content/66-msm-blog-jan-2009?start=20"

and rewrite to http://www.example.com

Is that clearer.

Also is there a good book on this subject which explains this in laymans terms

Much appreciated

g1smd

11:21 pm on Nov 22, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



RewriteRule cannot and does not "change" URLs.

To change a URL, you must first change the references published and advertised on the links on the page.

Once that has been done, a RewriteRule accepts the URL request and changes the default internal filepath that the content will be fetched from.