简体   繁体   中英

mod_rewrite - writing regular expression for clean url and unclean url

If i have a mod rewrite code as following:

RewriteRule ^/(\w+)/?$ index.php?id=$1  

I'm new to mod-rewrites and i was wondering if a user enters a clean url instead of a unclean, eg

http://example.com/1000/

into browser rather than

http://example.com/index.php?id=1000

will i still be able to request the $_GET[] variable of 1000?

Thanks everyone.

Try this:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/? index.php?id=$1           [L,QSA]

I use RewriteRule ^/(\\w+)/?$ index.php?id=$1 just as you have ... And I assure you it works .. Have you enabled Mod Rewrites?

$ sudo a2enmod rewrite
$ sudo service apache2 restart

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM