我在 .htaccess 文件中遇到了一些问题
I have Some issue in .htaccess file
我在 .htaccess 中遇到了一些问题 file.I 已将我的索引页面托管到网络服务器。我不知道我在 .htaccess file.After 中做错了什么 在 .htaccess 文件中添加代码仍然是我的 url 不是 friendly.It 显示 http://rang.comli.com/servicecnt It should be http://rang.comli.com/servicecnt/service_id/5
<html>
<head>
<title>Second mod_rewrite example</title>
</head>
<body>
<p>
welcome index page. Index page is loaded
<a href="http://rang.comli.com/servicecnt.php?service_id=5">Done with php my admin</a>
</p>
</body>
</html>
这是我的 .htaccess 文件:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## hide .php extension
# To externally redirect /public_html/index.php to /dir/index
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /public_html/index to /dir/index.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
RewriteEngine On
RewriteCond %{QUERY_STRING} ^service_id=([0-9]*)$
RewriteRule ^servicecnt\.php$ /servicecnt.php/%1? [R=302,L]
您可以使用:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+servicecnt\.php\?service_id=([^\s&]+) [NC]
RewriteRule ^ servicecnt/service_id/%1? [R=302,L]
## hide .php extension
# To externally redirect /public_html/index.php to /dir/index
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
RewriteRule ^servicecnt/service_id/(\d+)/?$ servicecnt.php?service_id= [QSA,L]
## To internally redirect /public_html/index to /dir/index.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
您最好的选择不是重定向旧的 url,而是首先让 php 生成漂亮的 url。用户每次点击你的link,服务器都需要重定向用户,效率很低。如果用户改为单击新的 url,您只需在内部重写它。您可以使用以下规则将其重写回来:
RewriteRule ^servicecnt/service_id/([^/]+)/?$ servicecnt.php?service_id= [L]
我在 .htaccess 中遇到了一些问题 file.I 已将我的索引页面托管到网络服务器。我不知道我在 .htaccess file.After 中做错了什么 在 .htaccess 文件中添加代码仍然是我的 url 不是 friendly.It 显示 http://rang.comli.com/servicecnt It should be http://rang.comli.com/servicecnt/service_id/5
<html>
<head>
<title>Second mod_rewrite example</title>
</head>
<body>
<p>
welcome index page. Index page is loaded
<a href="http://rang.comli.com/servicecnt.php?service_id=5">Done with php my admin</a>
</p>
</body>
</html>
这是我的 .htaccess 文件:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## hide .php extension
# To externally redirect /public_html/index.php to /dir/index
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /public_html/index to /dir/index.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
RewriteEngine On
RewriteCond %{QUERY_STRING} ^service_id=([0-9]*)$
RewriteRule ^servicecnt\.php$ /servicecnt.php/%1? [R=302,L]
您可以使用:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+servicecnt\.php\?service_id=([^\s&]+) [NC]
RewriteRule ^ servicecnt/service_id/%1? [R=302,L]
## hide .php extension
# To externally redirect /public_html/index.php to /dir/index
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
RewriteRule ^servicecnt/service_id/(\d+)/?$ servicecnt.php?service_id= [QSA,L]
## To internally redirect /public_html/index to /dir/index.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
您最好的选择不是重定向旧的 url,而是首先让 php 生成漂亮的 url。用户每次点击你的link,服务器都需要重定向用户,效率很低。如果用户改为单击新的 url,您只需在内部重写它。您可以使用以下规则将其重写回来:
RewriteRule ^servicecnt/service_id/([^/]+)/?$ servicecnt.php?service_id= [L]