Forum Moderators: phranque

Message Too Old, No Replies

Rewrite Rule to Hide Directory in URL

Rewrite Rule to hide folder name in URL

         

kelsheikh

12:34 am on Nov 1, 2011 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hi,

I was wondering if someone could help me with a rewrite rule. I have my htaccess in the city directory folder.

I would like the following URL change.

[domain.com...]

to be

[domain.com...]

g1smd

1:43 am on Nov 1, 2011 (gmt 0)

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



What have you tried so far?

Use the previous 80 000 code examples in this forum for guidance.

lucy24

3:13 am on Nov 1, 2011 (gmt 0)

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



I would like the following URL change.

[domain.com...]

to be

[domain.com...]


Do you know what happened? Do you know how to prevent it? If not, you forgot to read the Forum Charter. The link doesn't exactly jump up & down and wave its arms for attention, but it is on this page.

kelsheikh

1:13 pm on Nov 1, 2011 (gmt 0)

10+ Year Member Top Contributors Of The Month



I have tried this so far...


RewriteEngine On
RewriteRule ^(.*)(.*).html$ city/index.php?st=$1&id=$2


also tried


RewriteEngine On
RewriteRule ^(.*)(.*).html$ index.php?st=$1&id=$2



Which hasn't worked. I am putting this rule in an .htaccess into the city directory. Should I be putting this in root htaccess? Does it make a difference?

lucy24

11:15 pm on Nov 1, 2011 (gmt 0)

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



:: pause to run around screaming in horror because g1 is too grownup to indulge the desire to do the same ::

Q.: What's worse than a leading (.*) ?
A.: Two leading (.*).

RewriteRule ^(.*)(.*).html$ index.php?st=$1&id=$2


It goes without saying that this rule does not do what is intended to do. So why don't you start by explaining in English what it is intended to do. Use www.example.com in your examples.

g1smd

12:19 am on Nov 2, 2011 (gmt 0)

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



The pattern (.*) means "everything".

So, the code (.*)(.*) means "everything" goes in $1, so what's left to go in $2?

I'm surprised you're not just seeing "500 Internal Server Error" here.

You need a better pattern. Additionally, literal periods in patterns must be escaped.

Add the [L] flag to every rule.

The rules you have shown in your post have "index.php" in them and are clearly some sort of rewrite.

In your question you asked for a redirect and there's no index.php in any of your examples.

Nothing matches up.

kelsheikh

12:23 am on Nov 3, 2011 (gmt 0)

10+ Year Member Top Contributors Of The Month



OK, let me start from the beginning.

I have a page that is

http://www.example.com/state/{stateAbbreviation}.html

In that page I have links that go a city page that passes two variables like so...

http://www.example.com/city/index.php?st={stateAbbreviation}&id={cityName}.html

but I want the URL to be:

http://www.example.com/{stateAbbreviation}/{cityName}.html

Getting rid of "city" in the URL.

In my root .htaccess I have tried the following but have found no success
RewriteRule ^([a-z]{2})/(.*)\.html /city/index.php?st=$1&id=$2 [L]
RewriteRule ^(.*)/(.*)\.html /city/index.php?st=$1&id=$2 [L]