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

kmbjn2e3  于 2023-10-23  发布在  Apache
关注(0)|答案(2)|浏览(190)

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

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

我试着实现这个

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

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

gr8qqesn

gr8qqesn1#

就像这样:

  1. # Default index
  2. DirectoryIndex index.php
  3. # disable directory listing and MultiViews
  4. Options +FollowSymLinks -MultiViews -Indexes
  5. # disable automatic addition of trailing / after a directory
  6. DirectorySlash Off
  7. RewriteEngine on
  8. # add .php extension
  9. RewriteCond %{REQUEST_FILENAME}.php -f
  10. RewriteRule ^(.+?)/?$ $1.php [L]
pb3skfrl

pb3skfrl2#

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

  1. RewriteEngine on
  2. # Specific rewrites
  3. RewriteRule ^da$ da.php [L]
  4. RewriteRule ^da/success$ success.php [L]
  5. # General rewrites
  6. RewriteCond %{REQUEST_FILENAME} !-d
  7. RewriteCond %{REQUEST_FILENAME}\.php -f
  8. RewriteRule ^(.*)$ $1.php [NC,L]
  9. # Default index
  10. DirectoryIndex index.php

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

展开查看全部

相关问题