简体   繁体   中英

Removing extensions with .htaccess but keeping Parameters causes unstyled page

I'm trying to build a construct for redirecting or "beautifying" URL.

I would like to achieve following result:

  • URL like domain.com/signup.php should be accessed by domain.com/signup
  • Paramers should work like domain.com/signup/HASH will lead to domain.com/signup.php?hash=HASH
  • If possible multiple parameters should be extendable like domain.com/signup/HASH/VERIFIED -> domain.com/signup.php?hash=HASH&status=verified

My current approach is

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA]

I tried a lot, but either it doesn't work or it will end in an unstyled page. Any suggestions?

Use absolute links in your pages.
If you use any graphics or links in your pages, don't use "relative links". Instead, make all your links "absolute links" that start with http://www.example.com/... .

Or a root-relative link, beginning the href value with / .

In your case: http://www.example.com/css/Stylesheet.css or /css/Stylesheet.css ;

You can also add in the html <head> : <base href="/">

If you only use parameters at the root of the site, you can use:

RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([^/]+)/?$ $1.php [L]

# with one parameter
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([^/]+)/([^/]+)/?$ $1.php?hash=$2 [L,NE,QSA]

# with two parameters
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ $1.php?hash=$2&status=$3 [L,NE,QSA]

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