简体   繁体   English

添加文本以重写规则

[英]Adding text to rewrite rule

So I am creating a URL shortener and in-order for this to work I will have to change my .htaccess file to change the URL from website.com/?id=myidhere to website.com/myidhere . 因此,我正在创建一个URL缩短器,并按此顺序工作,我将不得不更改.htaccess文件,以将URL从website.com/?id=myidhere更改为website.com/myidhere I have sorted this task out for numerals but I have no clue how to perform it for letters. 我已经为数字解决了这个任务,但是我不知道如何对字母执行该任务。 This is my .htaccess so far: 到目前为止,这是我的.htaccess:

RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /(index\.php)?\?id=([0-9]+)([^\ ]*)
RewriteRule ^ /%3?%4 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)/?$ /index.php?id=$1 [L,QSA]

So it rewrites the numerals but when i enter text in the id of the url it shows a 404 error. 所以它重写了数字,但是当我在url的id中输入文本时,它显示404错误。 Would someone be able to help me out? 有人可以帮我吗? Thanks. 谢谢。

我不确定它能否解决您的问题,但是要支持数字和/或文本,您的正则表达式必须为[a-zA-Z0-9]+

尝试这个

RewriteRule ^myidhere$ id=myidhere [NC,L]

try this .htaccess code 试试这个.htaccess代码

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ /index.php?id=$1 [L]

Now you can access your webpage from 现在,您可以从

website.com/myidhere

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM