在浏览器中显示漂亮 URL

Display Pretty URL in browser

我可以做出以下URL:

重定向到:

但我希望它显示:

在浏览器中但不是。

正在显示:

当我去 URL 时:

它应该显示

在浏览器中却显示:

我该怎么做?

这是我正在使用的:

RewriteEngine On
RewriteRule ^video1 /videos/video1.php [QSA,NC,L]
RewriteRule ^/videos/video1.php /video1  [R=301,L]

你试过了吗

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com
RewriteRule (.*) http://www.yoursite.com/ [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /index.html HTTP/
RewriteRule ^index.html$ http://www.yoursite.com/ [R=301,L]

来源:

https://www.branded3.com/blog/htaccess-mod_rewrite-ultimate-guide/

您忘记在正则表达式中添加结尾 $。 请试试这个:

RewriteEngine On
RewriteRule ^/video1$ /videos/video1.php [QSA,NC,L]
RewriteRule ^/videos/video1.php$ /video1  [R=301,L]

而不是

RewriteEngine On
RewriteRule ^video1 /videos/video1.php [QSA,NC,L]
RewriteRule ^/videos/video1.php /video1  [R=301,L]

您可以在/root/.htaccess

中使用以下规则
RewriteEngine on
#1--Redirect from "/videos/foo.php" to "/foo"--#
RewriteCond %{THE_REQUEST} /videos/([^.]+)\.php [NC]
RewriteRule ^ /%1 [NE,NC,L,R]
#2--Internally map "/foo" to "/videos/foo.php--#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /videos/.php [NC,L]

在测试之前清除浏览器的缓存。