我想重写.htaccess的一个URL,不得不说我无法找到答案,很多小时的搜索后一个问题。而且,它并不能帮助我的正则表达式的技能不是很大......
我的网址的基本格式是这样的: mysite/article.php?id=1
我想有这样直接的有一个网址: mysite/article/1/made-up-irrelevant-title-slug 。
现在的问题是,我想了文章是一个变量,例如,它可以被更改为页并会直接向类似: mysite/page.php?id=1 ,从的http:// mysite的。 COM /页/ 1 /虚构的页面名称。
如果有人知道如何正确地写,我将非常感谢!
解决方案 #打开修改可以 RewriteEngine叙述上 #不要重写现有的文件,目录或符号链接。 的RewriteCond%{} REQUEST_FILENAME -s [OR] 的RewriteCond%{} REQUEST_FILENAME -l [OR] 的RewriteCond%{} REQUEST_FILENAME -d 。重写规则^ * $ - [NC,L] #重写/组件/ ID /标题 - > COMPONENT.php?ID = ID 重写规则^([^ /] +)/(\ d +)/.*$ $ 1.PHP?ID = $ 2 [L]I am trying to rewrite a URL with .htaccess and had a question that I'm unable to find an answer to after many hours of searching. And, it doesn't help that my regex skills aren't that great...
The underlying format for my URLs is this: mysite/article.php?id=1.
I would like to have a URL like this direct there: mysite/article/1/made-up-irrelevant-title-slug.
The problem is, I'd like the article to be a variable such that it could be changed to page and would direct to something like: mysite/page.php?id=1, from mysite/page/1/made-up-page-name.
If anyone knows how this is properly written, I would be extremely grateful!
解决方案 # Turn on Rewrites RewriteEngine on # Do not rewrite existing files, directories, or symlinks. RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] # Rewrite /COMPONENT/ID/TITLE -> COMPONENT.php?id=ID RewriteRule ^([^/]+)/(\d+)/.*$ $1.php?id=$2 [L]
更多推荐
使用的.htaccess重写通过ID和文件名网址
发布评论