[英]issue with .htaccess url rewriting
I am trying to rewrite url. 我正在尝试重写url。 Below is my code in .htaccess.
以下是我在.htaccess中的代码。
RewriteEngine on
RewriteRule ^home?$ index.php
RewriteRule ^contact?$ contact.php
RewriteRule ^about?$ about.php
RewriteRule ^logout?$ logout.php
RewriteRule ^products?$ products.php
RewriteRule ^single-products/([0-9]+)$ single-products.php?product=$1
The pages without parameters works fine. 没有参数的页面工作正常。 But when I click on the page 'single-products' with parameters it displays like
但是,当我单击带有参数的“单一产品”页面时,它显示为
single-products/1
and images and css styles not worked. 以及图片和CSS样式无效。 When I changed the path css/syle.css to ../css/style.css it works.
当我将路径css / syle.css更改为../css/style.css时,它可以工作。 Another problem is I can't return to another pages.
另一个问题是我无法返回其他页面。 When I coming to single-products, and click another menu option, url will displays like,
当我进入单一产品时,点击另一个菜单选项,网址将显示为
single-products/about
and displays page not found error. 并显示页面未找到错误。 I requires /about.
我需要/ about。 My menu link should be
我的菜单链接应该是
<a href="single-products/1>Product 1</a>
How can I solve these issues. 我该如何解决这些问题。 I searched many sites for a solution and didn't find one.
我在许多站点上搜索了解决方案,但没有找到解决方案。 Anyone please help me.
有人请帮助我。 Thanks in advance...
提前致谢...
For folders to ignore such as CSS etc. try this before your last rewrite rule: 对于要忽略的文件夹(例如CSS等),请在最后重写规则之前尝试以下操作:
# Directories to ignore
RewriteRule ^(css|images|js)(/.*)?$ - [L]
You might also want to consider using this too, if you plan of having a robots file etc.: 如果您计划拥有机器人文件等,则可能还需要考虑使用此功能:
# Ignore favicon & robots.txt
RewriteRule ^favicon\.ico - [L]
RewriteRule ^robots\.txt - [L]
RewriteRule ^sitemap\.xml - [L]
You are missing a closing quote: 您缺少结束语:
<a href="single-products/1">Product 1</a>
As for your other question it's hard to answer as you haven't said how you want it to work.. 至于您的其他问题,由于您还没有说出您希望它如何工作,因此很难回答。
single-products/1
is how the rewite rule is set to work. 是如何设置重审规则的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.