0

Hi folks, I know this ain't php, but seemed the best place to put it for now.

Am trying to mod_rewrite the following:

http://www.nu.wetwork.org.uk/index.php?adran=first&tud=second
to
http://www.nu.wetwork.org.uk/first/second/

I'm a complete idiot when it comes to regex/apache, so any advice would be welcome. I have already managed to place 2 rules which:

1) renames nu.wetwork.org.uk to www.nu.wetwork.org.uk
2) gets rid of www.nu.wetwork.org.uk/index.php (and the index.html) to www.nu.wetwork.org.uk/

The second works OK as long as there is no querystring. Here's my ham-fisted attempt so far:

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^nu.wetwork\.org\.uk
RewriteRule ^(.*)$ http://www.nu.wetwork.org.uk/$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^GET\ .*/index\.(php|html)\ HTTP
RewriteRule ^(.*)index\.(php|html)$ /$1 [R=301,L]

In my test site, each page is referenced via index.php and querystring (always the 2 parameters). The faux-folders are just to give the site some structure / 'bookmarkability' for the user.

Thanks,
Ben.

Edited by diafol: n/a

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by diafol
0

Thanks for the reply cwarn, unfortuntely that changes faux folders to querystring - I need the opposite. I just can't work out the syntax required to change

/index.php?adran=$1&tud=$2

to

/$1/$2/

1

I believe that is the correct syntax however the files should be accessible with AND without rewritten urls. Also if you want to make sure apache doesn't get into an infinit loop causing a 500 error then you could use the following:

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^nu.wetwork\.org\.uk
RewriteRule ^(.*)$ http://www.nu.wetwork.org.uk/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?(.*)/(.*)/?$ /index.php?adran=$1&tud=$2

So to explain what those last three lines do, the two lines near the end beginning with RewriteCond% check that it is not rewriting a file or directory. Then the last line matches the regex on the left in the url and if that matches it views the page on the right similar to the preg_replace syntax. Is that what your after because you may need to just try viewing it in the new format and linking to the new format as both ways exist when using mod_rewrite?

Votes + Comments
Brilliant! thank you very much - I was going off my rocker!
0

cwarn - you are an absolute genius sir!
Thank you very much - worked like a charm!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.