简体   繁体   中英

Re-writing Dynamic URL with .htaccess

I'd like to remove the ".php" at the end of all webpages AND rewrite my dynamic urls for the section "example.com/archive?url=..."

What I got so far:

Options -MultiViews

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

This part works fine but now I also want to rewrite my dynamic urls for the following section of the website.

Old url: example.com/archive?url=test-article

New url: example.com/archive/test-article

RewriteRule ^archive/([^/]+)$ archive?url=$1

This part doesn't work. What am I missing here?

It's used for an addon domain so maybe this has something to do with the problem?

EDIT 1:

I put some garbage in my .htaccess file and it generates an error so I know for sure it's reading the file.

EDIT 2:

I disabled multiviews as proposed below but getting an internal server error now. This is the error log:

[Tue May 20 13:12:12 2014] [error] [client (ip)] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace

Edit 3: I found the solution

I solved the problem by changing the last rule into:

RewriteRule ^news/([^/]+)$ archive?url=$1

Most likely you have options MultiViews enabled.

You can disable that using:

Options -MultiViews

With MultiViews disabled it will not not serve /file.php when you request /file .

EDIT: As per your revised question you can do:

RewriteRule ^news/([^/]+)$ archive?url=$1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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