Regex 用不同的值重写URL
我希望我的URL从 e、 g 到 分别。这就是我目前所拥有的-- 我读了无数关于堆栈溢出的问题,但是关于GET值的部分似乎根本不起作用 -编辑-感谢anubhavas的帮助,我成功地解决了它:)这里是代码,供任何人查看Regex 用不同的值重写URL,regex,apache,.htaccess,mod-rewrite,url-rewriting,Regex,Apache,.htaccess,Mod Rewrite,Url Rewriting,我希望我的URL从 e、 g 到 分别。这就是我目前所拥有的-- 我读了无数关于堆栈溢出的问题,但是关于GET值的部分似乎根本不起作用 -编辑-感谢anubhavas的帮助,我成功地解决了它:)这里是代码,供任何人查看 RewriteEngine on Options +FollowSymLinks -MultiViews -Indexes #rewrites to without www. RewriteCond %{HTTP_HOST} ^www\.website\.com$ [NC] R
RewriteEngine on
Options +FollowSymLinks -MultiViews -Indexes
#rewrites to without www.
RewriteCond %{HTTP_HOST} ^www\.website\.com$ [NC]
RewriteRule ^(.*)$ http://website.com/$1 [R=301]
#makes it so php file types are hidden
RewriteRule ^(emailme)/?$ $1.php [L,QSA]
#makes it so GET values are hidden
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^(emailme)/([^/]+)/([^/]+)/?$ $1.php?type=$2&property=$3 [L,QSA]
RewriteRule ^(emailme)/([^/]+)/?$ $1.php?type=$2 [L,QSA]
这样做:
RewriteEngine on
Options +FollowSymLinks -MultiViews -Indexes
#rewrites to without www.
RewriteCond %{HTTP_HOST} ^www\.website\.com$ [NC]
RewriteRule ^(.*)$ http://website.com/$1 [R=301]
#makes it so file types are hidden
RewriteRule \.(css|jpe?g|gif|png|js|ico)$ - [L]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^(contactus|emailme)/([^/]+)/([^/]+)/?$ $1.php?type=$2&property=$3 [L,QSA]
RewriteRule ^(contactus|emailme)/([^/]+)/?$ $1.php?type=$2 [L,QSA]
不幸的是,该评论没有提供任何关于什么不起作用以及什么不对劲的信息。问题1。您使用了什么URL进行测试?这个.htaccess的位置是什么?你有其他规则吗?我提供了目前使用的所有规则。“make-GET-stuff-hidden”下面的部分对我来说已经不起作用了:o你可以在这里看到它:它现在可以工作了,但是页面有点…奇怪。首先,make-file-type-hidden现在不起作用(请参阅),并且页面似乎已丢失其格式。这是因为您的css/js链接使用相对路径。只需在css、js、图像文件中使用绝对路径,而不是相对路径。这意味着您必须确保这些文件的路径以
http://
或斜杠/
开头。您可以尝试在您的age的HTML头:
,因此每个相对URL都是从该URL而不是当前URL解析的。
RewriteEngine on
Options +FollowSymLinks
#rewrites to without www.
RewriteCond %{HTTP_HOST} ^www\.website\.com$ [NC]
RewriteRule ^(.*)$ http://website.com/$1 [R=301]
#makes it so file types are hidden
RewriteRule \.(css|jpe?g|gif|png|js|ico)$ - [L]
Options +MultiViews
Options -Indexes
#makes so GET stuff are hidden
RewriteRule ^contactus/([^/]*)/([^/]*)$ /contactus.php?id=$1&$2 [L,QSA]
RewriteEngine on
Options +FollowSymLinks -MultiViews -Indexes
#rewrites to without www.
RewriteCond %{HTTP_HOST} ^www\.website\.com$ [NC]
RewriteRule ^(.*)$ http://website.com/$1 [R=301]
#makes it so php file types are hidden
RewriteRule ^(emailme)/?$ $1.php [L,QSA]
#makes it so GET values are hidden
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^(emailme)/([^/]+)/([^/]+)/?$ $1.php?type=$2&property=$3 [L,QSA]
RewriteRule ^(emailme)/([^/]+)/?$ $1.php?type=$2 [L,QSA]
RewriteEngine on
Options +FollowSymLinks -MultiViews -Indexes
#rewrites to without www.
RewriteCond %{HTTP_HOST} ^www\.website\.com$ [NC]
RewriteRule ^(.*)$ http://website.com/$1 [R=301]
#makes it so file types are hidden
RewriteRule \.(css|jpe?g|gif|png|js|ico)$ - [L]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^(contactus|emailme)/([^/]+)/([^/]+)/?$ $1.php?type=$2&property=$3 [L,QSA]
RewriteRule ^(contactus|emailme)/([^/]+)/?$ $1.php?type=$2 [L,QSA]