URL结构的htaccess [英] url construction htaccess

查看:116
本文介绍了URL结构的htaccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以说我有一个链接到我的网页看起来像一个:mysite.com/48YSWD96,我需要它看起来像:mysite.com/?d=48YSWD96。我如何实现这一目标?我可以通过修改我的htaccess文件实现这一目标?目前看起来是这样的...

  RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_FILENAME} \ PHP -f
重写规则^([^ /] +)/ $ $ 1.PHP
重写规则^([^ /] +)/([^ /] +)/ $ /$1/$2.php

的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI}!(\ [A-ZA-Z0-9] {1,5} | /)$
重写规则(。*)/ $ 1 / [R = 301,L]
的RewriteBase /
 

解决方案

它看起来像你只需要追加这到底:

 的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^([A-ZA-Z0-9] +)$ /?ID = $ 1 [L]
 

有关它周围的其他方法工作:

 的RewriteCond%{QUERY_STRING}(^ |&安培;)ID =(A-ZA-Z0-9] +)($ |&安培;)
重写规则^ $ /%1 [L]
 

这将采取 mysite.com/?d=48YSWD96 的要求,改变URI来 / 48YSWD96 。从本质上讲,无论在 ID 等于在查询字符串。

Lets say I have a link to one of my page that looks like: mysite.com/48YSWD96, I need it to look like: mysite.com/?d=48YSWD96. How do I achieve this? Can I achieve this by modifying my htaccess file? which currently looks like this...

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
RewriteBase /

解决方案

It looks like you just need to append this to the end:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9]+)$ /?id=$1 [L]

For it to work the other way around:

RewriteCond %{QUERY_STRING} (^|&)id=([A-Za-z0-9]+)($|&)
RewriteRule ^$ /%1 [L]

This will take a request for mysite.com/?d=48YSWD96 and change the URI to /48YSWD96. Essentially, whatever the id equals in the query string.

这篇关于URL结构的htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆