简体   繁体   中英

Rewrite Rule for GET variables .htaccess

Well I'm havin trouble creating .htaccess , anyway I have categories in my menu for example test1 , test2 , test3 that are the names of a folders, and what I'm trying to do is to point the second parameter of the url to index.php , for example http://myapp/test1 I want to be able from the index.php to have $_GET['cat'] = test1 and so on..
Here's what I've tried so far and didn't work:

Options +FollowSymlinks
RewriteEngine on

RewriteRule ^(.*)/$ index.php?cat=$1 [NC,L]

Any help with this? Much appreciated.

Try removing the trailer / character from your rewrite rule. ^(.*)/$ matches any URL that ends in a / like http://myapp/test/ . You are probably looking for ^(.*)$ or to strip any leading slash ^/(.*)$ . Note though that if index.php is accessed directly via f.ex. http://myapp/index.php this would also match and rewrite to http://myapp/index.php?cat=index.php and any images wouldn't also be directly accesible. So you might want to add some RewriteCond that first checks if the requested URL is an existing file with RewriteCond %{REQUEST_FILENAME} !-f before the RedirectRule to rewrite the URL.

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