简体   繁体   中英

Htaccess Rewrite Pretty URL

there's probably a very simple answer to my question, but after hours of browsing I still haven't found a solution, so thank you very much for all your help. Perhaps I should mention that I'm using a subdomain with Bluehost (multiple domains on the same account).

I would like to rewrite: www.example.com/myfolder to www.example.com/index.php?s=myfolder

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /index.php?s=$1 [L]
  • example.com/abcd -> works
  • example.com/abcd/ -> works but destroys my picture URLs
  • example.com/abcd/index.php -> doesn't work (redirects me to main page)

Thank you very much for your help. Roland

Have you checked this: https://aloneonahill.com/blog/url-rewriting-for-beginners

and: URL rewriting with PHP

RewriteEngine on RewriteRule ^/?Some-text-goes-here/([0-9]+)$ /picture.php?id=$1

To rewrite to index, use:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)/?$ /index.php?s=$1 [L]

And for css, scripts, or pictures, use absolutes links (which begin with / or http://... ) or add <base href="/"> in html head.

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