Jump to content

Need help to modify this mod_rewrite rules


wilsonf1
 Share

Recommended Posts

I currently have a rewrite rule working perfectly fine for the following pages:directory/page1directory/page2directing to:directory/single-file.php?parameter=page1 directory/single-file.php?parameter=page2By doing this:RewriteRule ^directory/([^/\.]+)/?$ directory//single-file.php?parameter=$1 [L]But if I want the Urls to have .php on the end like this:directory/page1.phpdirectory/page2.phpHow do I edit this part of the rule?: ^directory/([^/\.]+)/?$thanks!

Link to comment
Share on other sites

Edit:After rereading your post I think I missunderstood. You are trying to parse .php into something. So this should work:

RewriteRule ^directory/(.*)\.php directory/single-file.php?single-file=$1

Try this. I'm a bit new at it myself. I'm not sure if the backslash is necessary before .php. But I think it is before a '.' your are trying to include in the search.Original:You can use RewriteCond like an IF statement. For my site I don't want to apply the rule for any extensions so this is what I do-

RewriteCond %{SCRIPT_FILENAME} !\.(gif|jpg|png|css|js|php|html|htm|zip)$ [NC]RewriteRule ^(.*)/(.*)$ index.php?page=$1&item=$2 [L]RewriteCond %{SCRIPT_FILENAME} !\.(gif|jpg|png|css|js|php|html|htm|zip)$ [NC]RewriteRule ^(.*)$ index.php?page=$1 [L]

RewriteCond %{SCRIPT_FILENAME} !\.(gif|jpg|png|css|js|php|html|htm|zip)$ [NC]

Using '!' says not. So if you don't find .gif or .jpg or .png (etc...) then do the rule below.

Edited by MrFish
Link to comment
Share on other sites

We usually just choose any locations that aren't files or directories:

RewriteCond %{SCRIPT_FILENAME} !-fRewriteCond %{SCRIPT_FILENAME} !-dRewriteRule ^directory/(.*)$ directory/single-file.php?parameter=$1 [L]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...