Wednesday 15 February 2012

PHP Href Handling/Rewriting -


I have .htaccess settings that will rewrite anything in index.php to create a fixed url. For example:

rewrite ^ (. *) $ Index.php? / $ 1 [L]

url: www.domain.com $ _ SERVER ['REQUEST_URI'] There is no problem with and I can handle the url. However, I have a problem in my links, for example:

and

When I click on this link, the URL will be www.domain.com/home/article/news/home/article/recent because the href value Not started with "/" .

Is it possible to rewrite my link in PHP or .htaccess? So when I forget to type in "/" in href, then it will not follow the current URL? Thank you.

.htaccess will not help you easily. I say this error is getting pronounced and difficult to maintain as you add new paths. If you want to go that route you should do it for 301 so that your users can see those weird ways. This will unfortunately add latency for redirection.

For PHP, it depends on how you prepare your output. I can say that this is possible, but you have to generate the link instead of the output. It is directly in the form of HTML which will replace ugly IMO.

This is definitely a very little effort and will quickly become a habit of using the full path.

No comments:

Post a Comment