Home rewrite rule to remove file extention and action
Reply: 1

rewrite rule to remove file extention and action

user1355300
1#
user1355300 Published in 2018-02-07 12:09:50Z

I'm trying to create a rewrite rule to remove file extention and action from it.

For example this url:

password.php?action=new

should be rewritten as:

password/new 

I am trying following:

RewriteRule ^password/([a-zA-Z]+)/?$ /password.php?action=$1 [L,QSA]

It does not seem to work.

Also instead of specifying password.php file, how can i generalize it for every file? For example

file1.php?action=edit
file1/edit

file2.php?action=something
file2/something
anubhava
2#
anubhava Reply to 2018-02-07 12:15:47Z

You can use this generic rule:

Options -MultiViews
RewriteEngine On

RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([\w-]+)/([\w-]+)/?$ $1.php?action=$2 [L,QSA]
  • RewriteCond %{DOCUMENT_ROOT}/$1.php -f checks for presence of corresponding .php file in site root directory before adding .php in front of it.
  • Options -MultiViews disables content negotiation features.
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.350854 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO