What is wrong in this rule?
RewriteRule ^page\?v=([^/]+)$ page.php?v=$1 [L,NC]
I just want to make the URL looks like that
http://www.domainname.com/page?sk=info
You don't have to include the query parts if they're not changing anyway.
RewriteRule ^page$ page.php [L,NC]
The RewriteRule will not match any part of the query string. page?v=123 will still become page.php?v=123
Also, your RewriteRule uses ?v= while you talk about ?sk=info
Also, you can find additional information about this mod_rewrite case here:
http://wiki.apache.org/httpd/RewriteFlags/QSA
And another SO entry about this issue here.
Related
I have 3 step in one php file:
This is my htacess now:
RewriteRule ^igra/(.*)$ "/index.php?page=igra&id=$1"
RewriteRule ^igra/(.*)/sezona/(.*)$ "/index.php?page=igra&id=$1&season=$2"
RewriteRule ^igra/(.*)/sezona/(.*)/liga/(.*)$ "/index.php?page=igra&id=$1&season=$2&league=$3"
When i go in browser something like index.php?page=igra&id=$1 or index.php?page=igra&id=$1&season=$2 or index.php?page=igra&id=$1&season=$2&league=$3 sure with real values it works fine, but when i try to access with this pretty links it always show me the first rewrite rule..
I hope u understand me what i need here, best regards..
Your first rule is capturing everything, so the subsequent rules never get executed. Just switch them around:
RewriteRule ^igra/(.*)/sezona/(.*)/liga/(.*)$ /index.php?page=igra&id=$1&season=$2&league=$3 [L]
RewriteRule ^igra/(.*)/sezona/(.*)$ /index.php?page=igra&id=$1&season=$2 [L]
RewriteRule ^igra/(.*)$ /index.php?page=igra&id=$1 [L]
Notice also the addition of the L flag.
I'm looking for a way to rewrite my URLs and am checking what htaccess can do for me.
I want to rewrite
domain.com/index.php?page=myPage&name=test
to
domain.com/myPage/?name=test
All tutorials I've found only shows how to do complex things but something as simple as this, isn't to be found anywhere.
What I have only rewrites "myPage" to "page=myPage" and ignores what I put after "?" in my URL
RewriteRule ^([^/\.]+)?$ index.php?page=$1 [L]
Notice that "name=test" could be anything (id=1, mode=edit, foo=bar).
Try adding the flag for "query string append" by changing [L] to [QSA,L]
Source: https://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_qsa
I have a url like:
http://www.site.com/profile.php?id=$id
And I want it to end up like:
http://www.site.com/$id
How could I do this in PHP or in htaccess?
You would need to create a rewrite rule in htaccess such as
RewriteRule ([0-9]+) profile.php?id=$1 [L]
This would rewrite anything with a 0-9 character to profile.php and pass the number in the query string. So you could do
site.com/1
Which would be
site.com/profile.php?id=1
N number of discussion gone already here. Anyway, here it is. :)
Your htacces rewrite rule,
RewriteEngine on
RewriteBase /
RewriteRule ^([0-9]+)$ profile.php?id=$1 [L]
Way to link in your PHP files,
Your URL
Make sure to replace $id with your values.
FYI, http://www.site.com/profile.php?id=$id will also works, avoid using it & use mask URL like i quoted above. :)
I seem to be lost in a big pile of code. I have the following piece of .htaccess code:
RewriteRule ^user/(.*)$ index.php?p=user/$1 [L]
RewriteRule ^user/(.*)/(.*)$ index.php?p=user/$1&id=$2 [L]
Now, I have a file called profile.php, inside that I use $_GET to get the ID. But when I go to /user/profile/1, it does nothing. When I go there without a ID, my script works. Can somebody help me out and tell me what I am doing wrong?
Thank you. Sorry for the confusing message.
Try these 2 rules:
RewriteRule ^user/([^/]+)/([^/]+)/?$ index.php?p=user/$1&id=$2 [L,QSA]
RewriteRule ^user/([^/]+)/?$ index.php?p=user/$1 [L,QSA]
Explanation:
Reason why your rule aren't working because your regex is wrong. You first rule ^user/(.*)$ has .* which is matching everything after /user/ hence your 2nd rule never fires and $_GET['id'] is always empty.
By changing that to [^/]+ my rule is matching only until next / is found hence both rules co-exist fine.
QSA is just nice flag to have here to preserve any existing query string.
With the new Diggbar, you can put http://digg.com in front of any URL that you are currently at and it will create a Digg short URL. I am only assuming they do this by modrewrite (though I am not sure since I am new at this all).
How is this done? It seems to me when I try this with a website I am working on, it bombs out.
I want to be able to do the following:
http://example.com/http://stackoverflow.com/question/ask
and have a modrewrite that will allow this to go to
http://example.com/index.php?url=http://stackoverflow.com/question/ask
But when I use this modrewrite:
RewriteEngine on
RewriteRule ^([A-Za-z0-9]+)$ /message.php?id=$1 [L]
it doesn't work. What am I doing wrong?
You have to take the value from the request line because Apache removes empty path segments. The initially requested URI path /http://foobar/ becomes /http:/foobar/. But the request line (THE_REQUEST) stays untouched:
RewriteCond %{THE_REQUEST} ^GET\ /(https?://[^\s]+)
RewriteRule ^https?:/ index.php?url=%1 [L]
You're only looking for letters and numbers in that regular expression, so it won't pick up the colon and slashes. You're also using index.php in the example and message.php in the htaccess ;)
You'll probably want something like this:
RewriteEngine on
RewriteRule ^http://(.+)$ /index.php?url=$1 [L]
This makes sure you only catch URLs here, and you can still have regular pages! (Think about what would have happened if you went to example.com/index.php, you'd end up in an infinite loop.)