创建一个漂亮的URL(Creating a Pretty URL)

系统教程 行业动态 更新时间:2024-06-14 16:57:17
创建一个漂亮的URL(Creating a Pretty URL)

它几乎类似于如何创建漂亮的网址,但它似乎并不适合我。

这是我的网址:

http://localhost/pr/ajax/ajax_load.php?task=get_blob&blid=199

我如何将其转换为:

http://localhost/pr/ajax/get_blob/199

这是我的.htaccess

RewriteEngine On RewriteBase /pr/ajax/ RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+pr/ajax/ajax_load\.php\?task=([&\s]+)&blid=([0-9]+) [NC] RewriteRule ^/%1/%2? [R=301,L,NE] RewriteCond %{ENV:REDIRECT_STATUS} !200 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^([^/]+)/([^/]+)/?$ /pr/ajax/ajax_load.php?task=$1&blid=$2 [L,NC,QSA,NE] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule \.(js|css|jpeg|gif|png|pdf)$ /pr/ajax/%{REQUEST_URI} [NC,L,R=302]

你应该把.htaccess放在哪里? 我的意思是,你把它放在哪里很重要? 我的根源是pr 。

It almost is similar to how to create pretty urls but, it does not seem to work for me.

Here is my url:

http://localhost/pr/ajax/ajax_load.php?task=get_blob&blid=199

How do I convert it to:

http://localhost/pr/ajax/get_blob/199

Here is my .htaccess:

RewriteEngine On RewriteBase /pr/ajax/ RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+pr/ajax/ajax_load\.php\?task=([&\s]+)&blid=([0-9]+) [NC] RewriteRule ^/%1/%2? [R=301,L,NE] RewriteCond %{ENV:REDIRECT_STATUS} !200 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^([^/]+)/([^/]+)/?$ /pr/ajax/ajax_load.php?task=$1&blid=$2 [L,NC,QSA,NE] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule \.(js|css|jpeg|gif|png|pdf)$ /pr/ajax/%{REQUEST_URI} [NC,L,R=302]

Where should the .htaccess be placed? I mean, does it matter where you put it at? My root is at pr.

最满意答案

试试这个:

RewriteEngine On RewriteRule ^/pr/ajax/(.*)/(.*)$ /pr/ajax/ajax_load.php?task=$1&blid=$2 [NC,L]

是的,你把htaccess文件放在哪里都很重要。 您将文件放在要修改/操作其路径的文件的目录中。

Try this:

RewriteEngine On RewriteRule ^/pr/ajax/(.*)/(.*)$ /pr/ajax/ajax_load.php?task=$1&blid=$2 [NC,L]

And yes, it does matter where you put the htaccess file. You put the file in the directory of the file whose path you want to modify/manipulate.

更多推荐

本文发布于:2023-04-12 20:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/0c04bc783b1fdc9bbc6620d7d6c39cf1.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:创建一个   漂亮   URL   Creating   Pretty

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!