Link to home
Create AccountLog in
Avatar of helpchrisplz
helpchrisplz

asked on

.htaccess write url

Hi all.

how can rewrite all my urls so they dont have:  /main.php?mod=

here is a few examples for urls on my site:

http://www.ecoadwaterlessurinals.co.uk/main.php?mod=benefits
http://www.ecoadwaterlessurinals.co.uk/main.php?mod=about
http://www.ecoadwaterlessurinals.co.uk/main.php?mod=research


this is what is currently in my .htaccess file:

AddType text/x-component .htc

Options +FollowSymLinks  
RewriteEngine on
RewriteBase /

RewriteCond %{THE_REQUEST} ^.*\/index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]
RewriteCond %{http_host} ^ecoadwaterlessurinals.co.uk$ [nc]
RewriteRule ^(.*)$ http://www.ecoadwaterlessurinals.co.uk/$1 [r=301,nc,L]
Avatar of ahoffmann
ahoffmann
Flag of Germany image

rewriting to what?
what is the URL you type in the browser?
Avatar of helpchrisplz
helpchrisplz

ASKER

RewriteCond   %{REQUEST_URI}  !^/main\.php
RewriteRule ^/+(.*)$ /man.php?mod=$1 [nc,L]
sorry about being slow. i have 5 upmarket brochure websites to build this month and got little time on my hands. i will try your code tomorrow.  ty
Hi your code didnt work.

This is what i got it working with:

#remove all crap from url when on sub pages and give the page a .html extension.
#i used http://www.generateit.net/mod-rewrite/ to auto generate the code below! :O
RewriteRule ^([^-]*)\.html$ /main.php?mod=$1 [L]
I've requested that this question be closed as follows:

Accepted answer: 0 points for helpchrisplz's comment #a38931757

for the following reason:

i found some code to do it
the example I posted is roughly the same as the " auto generate" one
the requirement that it should only match if there is no - in the URL is not part of the question (and I believe it is not wanted too)
When i used your code:

RewriteCond   %{REQUEST_URI}  !^/main\.php
RewriteRule ^/+(.*)$ /man.php?mod=$1 [nc,L] 

Open in new window


It didn't do any thing even when checking on other browsers.

when i used the auto generated code:
RewriteRule ^([^-]*)\.html$ /main.php?mod=$1 [L] 

Open in new window


it made both the following pages available:

http://www.ecoadwaterlessurinals.co.uk/main.php?mod=howtheywork
and
http://www.ecoadwaterlessurinals.co.uk/howtheywork.html

So the auto generated code did work best, but now i have 2 ways to get to the the same page.
i am looking for a way to 301 all pages to there .html URL if you can help with this i would give you the points.
I don't care about points, but the correct answer

if you say "when i used the auto generated code" does this mean that you do not use a RewriteCond ?
if so, what happens when you access /main.php ?
sorry ahoffmann if i've annoyed you.

I'm a noob with htaccess.

i dont have a actual page with just main.php. its allways with ?mod=pageName at the end.

by  "when i used the auto generated code" i mean the code i got from the auto generator website : http://www.generateit.net/mod-rewrite/ 

all i need is a way to get all my pages to not have all the mod= crap and my navigation needs to point to the new rewrited urls but they are hard writen to go to the ?mod= pages.
so i was thinking a 301 would do it.
if i access

/main.php?mod=howtheywork

with your code nothing happens. i need it to redirect to the .html version:

/howtheywork.html
ahh, I see: my code is based on your comment Id 38905215 where there is no .html extension

> ...  now i have 2 ways to get to the the same page.
that's what the rewrite is for, obviously ;-)

> .. my navigation needs to point to the new rewrited urls but they are hard writen to go to the ?mod= pages.
hmm, hence you need the rule the other way around if you don't want to change your code

still sounds confusing what you have, what you want and what actually works ...
How can i make it redirect the other way around?
am thinking like this:

#make the html page availble
RewriteRule ^([^-]*)\.html$ /main.php?mod=$1 [L]

#now force a redirect from main to html version so my navigation links go to the html pages
RewriteCond   %{REQUEST_URI}  !^/main\.php
RewriteRule /main.php?mod=$1 ^/+(.*)$ [R=301,L]

but am just guessing what the code to do that would look like.?
ASKER CERTIFIED SOLUTION
Avatar of helpchrisplz
helpchrisplz

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
this is a better answer