开发者

htaccess to modify URL

开发者 https://www.devze.com 2023-03-06 02:09 出处:网络
I have the urls: http://example.com/at and want to get: http://example.com/at/index.php?at= http://example.com/at/

I have the urls:

http://example.com/at
and want to get:
http://example.com/at/index.php?at=

http://example.com/at/
and want to get:
http://example.com/at/index.php?at=
开发者_StackOverflow中文版
http://example.com/at/1asSde
and want to get:
http://example.com/at/index.php?at=1asSde

Also I am modifying the .htaccess located at the folder 'at'

I've been trying:

RewriteEngine On
RewriteRule (.*)$ index.php?at=$1 [QSA,L]

but am getting errors later when running the script of the site.

What can I try instead in order to get the correct results?

Thanks.


Try the following

RewriteEngine On
RewriteRule ^at/(.*)$ at/index.php?at=$1 [QSA,L]

You don't need a rule for at so long as at/index.php is a physical location. I would encourage you to create a better match for at. For example change (.*) to (\w+) if it can only be alphanumeric.


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


RewriteEngine On
RewriteRule ^at/(.*)$ index.php?at=$1 [QSA,L]


You will want to make sure that the resource you're trying to get doesn't exist before rewriting the URL:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)$ index.php?at=$1 [QSA, L] #didn't test to make sure this line actually works.
0

精彩评论

暂无评论...
验证码 换一张
取 消