Forum Moderators: phranque

Message Too Old, No Replies

syntax in mod rewrite

very simple question (I think)

         

bcrbcr

6:54 pm on Jun 2, 2007 (gmt 0)

10+ Year Member



I have already in mod rewrite this :
Options +FollowSymlinks
RewriteEngine on
rewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html?\ HTTP/ [NC]
rewriteRule ^index\.html?$ http://www.example.com/ [R=301,L]
rewriteCond %{HTTP_HOST} !^www\.example\.com(:[0-9]+)?$
rewriteRule (.*) http://www.example.com/$1 [R=301,L]

I am renaming directories from very long and bady formed names (with spaces in them) to more specific and shorter names.

So I need a redirect for an entire directory.

Looking through the posts here it seems that something like

rewriteRule ^/"whatever I have"/(.*)$ http://www.example.com/whatever-i-have/$1 [R=301,L]

might work ... but doesn't

Sounds lame - but can someone correct my syntax. Where do the "" go?

also - do I create the new directory with the shortest possible name? or include some keywords in the directory name?

eg
www.example.com/keyword-name-directory/filename.htm

Google seems to highlight these words in search results. Or is this spurious?

Thanks for all here (as always)

bryan

[edited by: jdMorgan at 12:12 am (utc) on June 5, 2007]
[edit reason] example.com [/edit]

bcrbcr

7:54 pm on Jun 2, 2007 (gmt 0)

10+ Year Member



OK
Have fixed this in a simple way

Using simple redirect 301 instead of mod rewrite

redirect 301 "/whatever I Have/" http://www.example.com/whatever-i-have/

seems to work OK - much simpler - why would we use mod rewrite for this (as seen in previous posts)? of have I short circuited something

Bryan

[edited by: jdMorgan at 12:13 am (utc) on June 5, 2007]
[edit reason] example.com [/edit]

bcrbcr

7:54 pm on Jun 2, 2007 (gmt 0)

10+ Year Member



OK
Have fixed this in a simple way

Using simple redirect 301 instead of mod rewrite

redirect 301 "/whatever I Have/" http://www.example.com/whatever-i-have/

seems to work OK - much simpler - why would we use mod rewrite for this (as seen in previous posts)? of have I short circuited something

Bryan

[edited by: jdMorgan at 12:13 am (utc) on June 5, 2007]
[edit reason] example.com [/edit]

jdMorgan

12:18 am on Jun 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The main reason not to mix mod_rewrite and mod_alias directives as you have done is that it is the server configuration that will then determine which directives will execute first. In most cases (most hosting companies), all mod_alias directives will always execute before any mod_rewrite directives, regardless of their order in your .htaccess file.

So, if it works on your current server and you don't plan to change hosting companies, it's OK.

Jim