简体   繁体   English

htaccess将example.com/user.php?id=username重写为example.com/username

[英]htaccess rewrite example.com/user.php?id=username to example.com/username

Title says it all im having trouble rewriting the following urls 标题说,所有这些都无法重写以下网址

The original URL: example.com/user.php?id=username 原始网址: example.com/user.php?id=username

The rewritten URL: example.com/username 重写的URL: example.com/username

My .htcacess code is: 我的.htcacess代码是:

RewriteEngine On
RewriteRule ^([^/]*)$ /user.php?id=$1 [L]

What the issue? 什么问题

The rewrite engine will loop, which means the rewritten URI ( /user.php ) matches the same pattern and gets applied again. 重写引擎将循环,这意味着重写的URI( /user.php )匹配相同的模式并再次应用。 Try adding some conditions: 尝试添加一些条件:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)$ /user.php?id=$1 [L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将example.com/section.php?username=xyz重写为example.com/xyz/section - Rewriting example.com/section.php?username=xyz to example.com/xyz/section 使用,htaccess将example.com?id=12重定向到example.com/index.php?id=12 - using ,htaccess redirect example.com?id=12 to example.com/index.php?id=12 如何使用户系统为example.com/username - How to make users system example.com/username 如何将example.com/index.php#anchor的URL重写为example.com/anchor? - How do I rewrite the URL for example.com/index.php#anchor to example.com/anchor? htaccess example.com/page.php?cat=berlin&page=2到example.com/berlin/2 - htaccess example.com/page.php?cat=berlin&page=2 to example.com/berlin/2 .htaccess用于分页以重定向example.com/page/page_id - .htaccess for pagination to redirect example.com/page/page_id 如何使用 .htaccess 重写 example.com/catelogue.php?page=3&cat1=fruit&cat2=apple - How to rewrite example.com/catelogue.php?page=3&cat1=fruit&cat2=apple with .htaccess 如何使用.htaccess将http://example.com/test.php设置为http://example.com/index.php?do=test? - How to make http://example.com/test.php to http://example.com/index.php?do=test using .htaccess? example.com/wp-login.php将我重定向到example.com/example.com/wp-admin - example.com/wp-login.php redirects me to example.com/example.com/wp-admin example.herokuapp.com 重定向到 example.com - PHP - example.herokuapp.com redirection to example.com - PHP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM