开发者

Simple URL Mod_rewrite

开发者 https://www.devze.com 2023-01-18 19:27 出处:网络
Why does the following htaccess file generate 300 errors, when this URL is called? 开发者_Python百科

Why does the following htaccess file generate 300 errors, when this URL is called?

开发者_Python百科

URL: hxxp://subdomain.domainame.com/keyworda/

IndexIgnore *

RewriteEngine on
RewriteRule ^([a-z]+)/$ /index.php?p=$1

Error log: 300 hxxp://subdomain.domainame.com/keyworda (no trailing slash)


Edit, I was trying to keep my answer short, I didn't mean for you to add this line exactly. It was just to show where the missing slash should go.

RewriteRule ^/([a-z]+)/$ /index.php?p=

I'm assuming you are editing a .conf file, in your apache config directory. Chigley's answer is assuming you are editing a per-directory .htaccess config file.

Edit your conf file to look like this:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{REQUEST_METHOD} ^TRACE
  RewriteRule .* - [F]
  RewriteRule ^/(test[a-z]+)/$ /index.php?id=$1 [L,R=301]
  ... your current stuff afterwords ...
</IfModule>
  • I think the problem is you need the initial '/' in yoru RewriteRule.
  • Putting my test RewriteRule first will make sure it is the one matching.
  • I added in the "test" prefix, so this line wont interfere with the rest of your website. This will make it easier to isolate this rule. So, when testing, the url must end with a "/" and begin with "test" for it to match, in addition to having 1 or more a-z.
  • The url to test is: hxxp://...yourserver.../testkeyword/
  • This should change the url in your browser to: hxxp://...yourserver.../index.php?id=testkeyword
  • The 404 error you are seeing can mean: 1) No rules match, and there is no file that matches your keyword. 2) One or more rules match, but the resulting url does not match your php files.

Once it's working, this is the real RewriteRule to use in your conf file:

RewriteRule ^/([a-z]+)/$ /index.php?id=$1 [L,R=301]

If it does not work, edit your question to include the full code in the block, and your httpd version, like this:

# httpd -v
Server version: Apache/1.3.33 (Darwin)
Server built:   Mar 20 2005 15:08:27

Probably doesn't matter, but just incase...

Here is the mod_write documentation. There are some examples at the very bottom.


can you try this one:

RewriteRule ^([^/]+)/?$ /index.php?p=$1


Try

RewriteRule ^([a-z]+)/?$ /index.php?p=$1 [L]
0

精彩评论

暂无评论...
验证码 换一张
取 消