我读了很多Q&在这里,但未能找到有效的解决方案。我想将URL从扁平链接语法更改为“常规”查询。
我如何从中得到:
http://localhost/start/__developer/pages/12016652
到此:
http://localhost/start/__developer/pages/suche.php?objektnr=12016652
通过htaccess或PHP的方式?请忽略curlies。在此先感谢您的支持!
此时我正在尝试这个:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteBase /start/__developer/immo-shg-v4/pages/
RewriteRule ^([0-9]+)$ suche.php?objektnr=$1 [QSA,L,NC]
解决方案:
RewriteRule ^([0-9]+)$ suche.php?objektnr=$1 [L,NC,NE,R]
[R]标志强制重定向。 http://httpd.apache.org/docs/2.2/rewrite/flags.html
答案 0 :(得分:2)
通过httpd.conf启用.htaccess它尚未启用,并将这些行放在DOCUMENT_ROOT文件夹中的.htaccess文件中:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-f
#This is your redirect rule
RewriteCond %{QUERY_STRING} !(?:^|&)objektnr=([^&]*)(?:&|$) [NC]
RewriteRule ^(start/__developer/pages/)([^/]*) $1suche.php?objektnr=$2 [L,NC,QSA]
根据你的评论,下面有另外一个像这样的RewriteRule:
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} !(?:^|&)objektnr=([^&]*)(?:&|$) [NC]
#This is your modified redirect rule
RewriteRule ^(start/__developer/immo-shg-v4/pages/)([^/]*) $1suche.php?objektnr=$2 [L,NC,QSA]