使用的.htaccess重写通过ID和文件名网址重写、文件名、网址、htaccess

由网友(一枕庭前雪)分享简介:我想重写.htaccess的一个URL,不得不说我无法找到答案,很多小时的搜索后一个问题。而且,它并不能帮助我的正则表达式的技能不是很大...... 我的网址的基本格式是这样的: http://mysite.com/article.php?id=1 我想有这样直接的有一个网址: http://mysite.com/a...

我想重写.htaccess的一个URL,不得不说我无法找到答案,很多小时的搜索后一个问题。而且,它并不能帮助我的正则表达式的技能不是很大......

我的网址的基本格式是这样的: http://mysite.com/article.php?id=1

我想有这样直接的有一个网址: http://mysite.com/article/1/made-up-irrelevant-title-slug

现在的问题是,我想了文章是一个变量,例如,它可以被更改为并会直接向类似: http://mysite.com/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]
 

网站 重定向 文件名 问号 如何让你的网站也能跟我的一样使用HTTPS访问

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: http://mysite.com/article.php?id=1.

I would like to have a URL like this direct there: http://mysite.com/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: http://mysite.com/page.php?id=1, from http://mysite.com/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]

阅读全文

相关推荐

最新文章