简体   繁体   English

重写动态URL无效(htaccess)

[英]Rewriting dynamic URLS not working (htaccess)

Im aware this is a question asked a lot and i have viewed them all trying so many different variations but it wont work and i dont know what im doing wrong. 我知道这是一个经常被问到的问题,我已经看过他们所有人都尝试了许多不同的变体,但都行不通,而且我不知道我在做什么错。 I created a .htaccess file a long time ago in order for it to point to my 404 error page which is has done fine for me but i want to rewrite the urls on my site now as there are a lot of posts and its getting messy with all the variables in the url. 我很久以前创建了一个.htaccess文件,以使其指向我的404错误页面,这对我来说还算不错,但是由于有很多帖子并且它变得凌乱,我现在想重写我网站上的网址网址中的所有变量。 i have a page called viewpost.php which gets passed 1 variable (there are other pages aswell but this is for the example) viewpost gets passed 1 variable so it becomes /viewpost.php?ID=10 我有一个名为viewpost.php的页面,该页面传递了1个变量(还有其他页面,但这只是示例)viewpost被传递了1个变量,因此它变为/viewpost.php?ID=10

RewriteEngine on
RewriteRule viewpost-ID-(.*)\.htm$ viewpost.php?ID=$1   

i added these 2 lines to the htaccess file. 我将这两行添加到htaccess文件中。 i tried removing the 404 code form the file and saved it but it didnt make it work either. 我尝试从文件中删除404代码并将其保存,但也没有使其工作。 Is there something else i need to be doing other than adding this code to the .htaccess file? 除了将此代码添加到.htaccess文件之外,我还需要做其他事情吗? the site is currently being hosted on atspace 该网站目前托管在atspace

Hosting OS  Proprietary *nix
Perl version    5.8.4
MySQL version    5.1
Perl path   /usr/bin/perl
Sendmail path   /usr/local/bin/sendmail
CGI-BIN path    not required    (You can run CGI, Perl scripts from any domain/subdomain folder)
Perl Modules    2900+ installed modules    (Click here to view the full list)
PHP Version  5.2.17 Change
PHP.INI Edit
PHP Info    [View PHP5.2.17 Info] [View PHP5.3.6 Info]
Directory Protection     Enabled  

this is what is written on the hosting settings page. 这就是在主机设置页面上写的内容。 im not sure whats required for the to be able to rewrite a url but since the .htaccess file is currently working for my 404 page im assuming its set up fine? 即时通讯不知道要重写网址需要什么,但由于.htaccess文件当前适用于我的404页,即时通讯假定设置正确?

Maybe some other rules in the .htaccess file are overriding your rule or you could be having a case-sensitive issue. .htaccess文件中的某些其他规则可能会覆盖您的规则,或者您可能遇到区分大小写的问题。 Add [NC,QSA,L] at the end of the RewriteRule line. RewriteRule行的末尾添加[NC,QSA,L]

RewriteEngine On
RewriteRule viewpost-ID-(.*)\.htm /viewpost.php?ID=$1 [NC,QSA,L]

NC ignores the case, QSA appends any extra query string parameters to the destination URL and L tells Apache to stop processing more RewriteRule entries if this is matched for the current URL. NC忽略了这种情况, QSA在目标URL后面附加了任何额外的查询字符串参数,并且L告诉Apache如果与当前URL匹配,则停止处理更多RewriteRule条目。

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

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