Apache Mod Rewrite for Pretty URLs isn't working

后端 未结 4 527
你的背包
你的背包 2021-01-15 02:13

I\'m trying to figure out how to do an apache mod_rewrite to remap $_GET.

What I\'m trying to accomplish:

Currentl

4条回答
  •  情深已故
    2021-01-15 02:54

    You approach seems fine but your RewriteCond doesn't match your requirements:

    RewriteCond %{REQUEST_URI} ^index.php?URL=pages
    

    means "rewrite the URL if someone requests something that starts with 'index.php"—but that's not what anyone will be requesting. You want your visitors to request pretty URLs.

    If your server only needs to serve those requests for /the-page, you can drop the condition entirely. Then any URL will be rewritten. (Note: This might not be what you want!)

    Otherwise, the condition should read something like this:

    RewriteCond %{REQUEST_URI} ^[a-z0-9-_]{1,40}
    

    If you don't want to mess with regular expressions, you could also try this:

    RewriteCond %{REQUEST_FILENAME} !-f  
    

    which means "if the user requests a URL for which no file can be found, rewrite the URL according to the upcoming RewriteRule."

提交回复
热议问题