[英]Pretty url not redirecting, htaccess
I'am quite new with htaccess.我对 htaccess 很陌生。 I have successfully created .htaccess file with following rules to redirect user with pretty url.
我已经成功创建了 .htaccess 文件,并使用以下规则重定向具有漂亮 url 的用户。
My actual url我的实际网址
http://localhost/domain.com/Job-Details.php?Job_ID=30
What i want to achieve我想要达到的目标
http://localhost/domain.com/30
My Current htaccess我当前的 htaccess
RewriteEngine On
RewriteBase /domain.com/
# Get the URI-path directly from THE_REQUEST variable
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\s/(.*)\.php [NC]
# Search friendly URLs for job detail page
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)$ Job-Details.php?Job_ID=$1 [NC,L,R=301]
Issues I'am facing我面临的问题
any idea what wrong i'am doing here.知道我在这里做错了什么。
Please try with the following /domain.com/.htaccess
code:请尝试使用以下
/domain.com/.htaccess
代码:
RewriteEngine On
RewriteBase /domain.com/
# Redirect actual URI to SEF URI
RewriteCond %{THE_REQUEST} (?:GET|HEAD)\s\/domain.com\/Job\-Details\.php\?Job_ID\=(\d+) [NC]
RewriteRule ^ %1? [R=302,L,NE]
# SEF URI for Job-Details page
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(\d+)$ Job-Details.php?Job_ID=$1 [NC,QSA,L]
Change R=302
to R=301
if you are happy with the results.如果您对结果满意,请将
R=302
更改为R=301
。 Remember to clear your cache before testing this, otherwise your browser may redirect based on historical cache.请记住在测试之前清除缓存,否则您的浏览器可能会根据历史缓存进行重定向。
Change this:改变这个:
RewriteRule ^([0-9]+)$ Job-Details.php?Job_ID=$1 [NC,L,R=301]
RewriteRule ^([0-9]+)$ Job-Details.php?Job_ID=$1 [L,QSA]
With R=301 you were creating a 301 redirection.使用 R=301 您正在创建 301 重定向。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.