Right now I have the following: (this is all that is in the .htaccess file under the /page/ dir)
RewriteRule ^(.*)$ set.php?numbers=$1 [QSA,L]
This correctly pulls with the following URL:
http://domain.com/location/page/XXX/
However, when the page loads I have the following links I want to click:
http://domain.com/location/page/set.php?numbers=XXX&otherset=morenumbers
Issue:
The other link does not seem to work because the HTACCESS rules are breaking the query strings. Is there a way around this so that the links work and that htaccess does not break it?
Related
I'm trying to convert my app links, so that a link like this:
http://localhost/index.php?id=13&category=Uncategorized&title=just-a-link
gets converted to this:
http://localhost/13/Uncategorized/just-a-test
so far I was able to do it using:
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /index.php?id=$1&category=$2&title=$3 [QSA,L]
but that completely breaks links to css and other files as it redirects every request with query to index.php
so I changed it slightly so that it only runs when the first query is a number:
RewriteEngine On
RewriteRule ^([0-9]*)/([^/]*)/([^/]*)$ /index.php?id=$1&category=$2&title=$3 [QSA,L]
this one doesn't break css and js files, however when you go to the link for example http://localhost/13/cat/test then try to go to another link like http://localhost/19/Uncategorized/something by clicking on it inside the previous page it will instead redirect you to something like http://localhost/13/Uncategorized/19/Uncategorized/just-a-test
How do I achieve what I described without any of these weird side effects??
Use :
RewriteEngine On
RewriteRule ^([0-9]+)/([^/.]+)/([^/.]+)/?$ /index.php?id=$1&category=$2&title=$3 [QSA,L]
And add this code to your html <header>:
<base href="/">
OR
<base href="http://www.domain.com/">
To fix relative css and js links
i have 2 questions regarding .htaccess,
1- if i use .htaccess to rewrite the url's on my website does it affect any of the requests or do i need to change the link for all forms for example if a action post for a form is index.php?submit do i need to change that link ? when i for example hide .php extension in .htaccess or it doesn't affect it
2-how do i basically hide all .php extensions
3- if i have the below url
www.link.com/post.php?post_id=53&post_name=the-International-day-in-roma
how do i make .htaccess rewrite it to the following
www.link.com/post/the-International-day-in-roma
does it matter if there was commas or can we remove them also ?
www.link.com/post.php?post_id=53&post_name=everyday,-or-today,-or-tomorrow
you can hide php file name in htaccess
for example if someone click this link
www.link.com/post/the-International-day-in-roma/
htaccess file contverts the url to post.php and call the the post name by $1
it represents this part "/([a-zA-Z0-9_-]+)/" the it is dynamic and it can be changed !
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^post/([a-zA-Z0-9_-]+)/$ post.php?post_id=53&post_name=$1 [L]
I decided to use mod_rewrite to make my URLs look better. I created very simple rules:
RewriteEngine on
RewriteBase /
RewriteRule ^(profile|contact|help|events|account|logout)/?$ index.php?p=$1 [NC]
RewriteRule ^home/?$ index.php [NC]
RewriteRule ^PlaceOrder/([0-9]+)/?$ index.php?p=mos&gc=$1 [NC]
It almost works well but it doesn't. So for example, [NC] is supposed to make it case-insensitive. However, for some reason, when I type for example localhost/Help in the browser, for some strange reason, it redirects to home page.
Another issue is with the last rule. If I type in localhost/PlaceOrder/1 it works as expected and opens index?p=mos&gc=1. But after that if I click on, for example, Account button, the browser uses this URL: localhost/PlaceOrder/account. Which is wrong. It should only use localhost/account. Why is it adding that sub-directory in there? It is only happening after the last rule is used. Prior to using the last rule, all links work well.
I'm going to guess that the localhost/Help isn't because of the rules and because of something in your index.php script. There's nothing those rules do that could possibly rewrite Help to the home page.
The second issue is a matter of a relative vs absolute URL issue. You're probably using relative links in your pages and because you've changed your relative URL base (which would be /PlaceOrder/ all relative links will have that prepended to it. You need to either change all your links to absolute URLs (they'd start with a /) or add this to your page's header:
<base href="/" />
I've googled for some mod_rewrite tutorials, but couldn't figure out how to solve my specific problem regarding the way I created my site with includes.
I've an index.php and in this file there are several includes like index.php?s=events will include events.php and so on.
If I use this code:
RewriteEngine on
RewriteRule ^/?([a-zA-Z_]+)$ index.php?s=$1 [L]
it will result that www.mydomain.com/events just shows the events.php itself, not with the "skeleton/framework" index.php around it, like it should be. So it just loads the specific included file.
My target is to call www.mydomain.com/events for example to show the whole index.php?s=events page.
Try putting slash before URL into the RewriteRule:
RewriteEngine on
RewriteRule ^/?([a-z_]+)$ /index.php?s=$1 [L,NC]
I added NoCase flag to get rid of capital letters in the regexp.
I want to make my URL clean. Below is what I want to do:
Dirty URL: www.site.com/index.php?page=products
Clean URL: www.site.com/products/
For this, I write these codes in .htaccess file:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]*)/$ /index.php?page=$1
But whenever I click on the links in my project, I redirect to localhost page. Links are in this form:
Products
I think it may be related to href value.
What's the correct form for href value? href="product",href="/product/",etc. ?
There is no correct form for your href attribute, each form acts in different ways:
Products
The above would go relatively from the page you are currently on, so might be domain.com/products but might be domain.com/shop/products
You are better using a link direct from the root by using a / at the start, for example:
Products
would go to domain.com/products (note the lack of a / at the end of the url, which will make it not work with your current htaccess rule)
To make both /products and /products/ go to the correct place, change your htaccess rule to:
RewriteRule ^([^/]*)/?$ /index.php?page=$1
The ? will make the character preceding it optional, so the / in this case.