apache 漂亮的URL与.htaccess重写引擎

kmbjn2e3  于 7个月前  发布在  Apache
关注(0)|答案(2)|浏览(97)

Hej
我试图实现一个漂亮的网址为我的网站重写引擎。目标是这样的- mysite.dk/da、mysite.dk/da/success和mysite.dk/da#scroll。
到目前为止,我的htaccess文件看起来像这样:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
DirectoryIndex /index.php

我试着实现这个

RewriteRule ^da$ da.php [L]
RewriteRule ^da/success$ success.php [L]

但这真的没有帮助:/谢谢

gr8qqesn

gr8qqesn1#

就像这样:

# Default index
DirectoryIndex index.php

# disable directory listing and MultiViews
Options +FollowSymLinks -MultiViews -Indexes

# disable automatic addition of trailing / after a directory
DirectorySlash Off

RewriteEngine on

# add .php extension 
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
pb3skfrl

pb3skfrl2#

要实现你想要的漂亮URL,修改你的.htaccess文件如下:

RewriteEngine on

# Specific rewrites
RewriteRule ^da$ da.php [L]
RewriteRule ^da/success$ success.php [L]

# General rewrites
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

# Default index
DirectoryIndex index.php

1.将dada/success的特定规则放在顶部,以便它们优先。
1.使用[L]停止对这些特定情况的进一步重写。
1.一般规则在具体规则之后。

相关问题