.htaccess 重写是冲突的/漂亮的 url

.htaccess rewrites are conflicting / pretty urls

我有一个网站,其中 url 看起来像这样: 示例。com/sample?m=1389&t=name-title

但我希望它看起来像这样: 示例。com/1389/name-title

我认为两个重写是冲突的。第一个是删除每个页面的 .php,第二个是使 sample.php 对搜索引擎优化更友好。这是我的整个 htaccess 代码。让我知道我做错了什么。我不想要文件扩展名,我希望我的页面 urls 看起来非常漂亮。谢谢你。

Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]

# Remove www from any URLs that have them:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ http://example.com/ [R=301,L]

Options All -Indexes

ErrorDocument 403 http://example.com/tapes.php
ErrorDocument 404 http://example.com/404

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 month"
ExpiresByType image/jpeg "access 1 month"
ExpiresByType image/gif "access 1 month"
ExpiresByType image/png "access 1 month"
ExpiresByType text/css "access 1 week"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access 1 month"
</IfModule>
## EXPIRES CACHING ##

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

# Or, compress certain file types by extension:
<files *.html>
SetOutputFilter DEFLATE
</files>

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)\.html$ /sample?m=&t= [L]

您可以在根 .htaccess 中使用它:

Options +FollowSymlinks -MultiViews -Indexes
RewriteEngine on
RewriteBase /

# Remove www from any URLs that have them:
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ http://example.com/ [R=301,L]

# remove php
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]

# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+sample\?m=([^&]+)&t=([^\s&]+) [NC]
RewriteRule ^ /%1/%2? [R=301,L,NE]

# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(\d+)/([^/]+)/?$ sample.php?m=&t= [L,QSA,NC]

# add php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]

ErrorDocument 403 http://example.com/tapes.php
ErrorDocument 404 http://example.com/404