im quite new to rewrite rules.
I can manage with one variable and thats it.
I have webpage Where the rewriterule is:
RewriteCond %{HTTP_HOST} ^www\.someserver\.com$
RewriteRule ^/?$ "http\:\/\/someserver\.com\/" [R=301,L]
RewriteRule ^(\d+)*$ ./index.php?comp=$1
RewriteRule ^(\d+)*/$ ./index.php?comp=$1
And it all work fine as it should. But now as i want 1 more variable into URL
i cant get it to work.
Right now the $1 is only numbers.
someserver.com/1554886
But i want two variable.
someserver.com/1554886-SOMENAME-WHATEVER-WORD-AND-HOW-MANY
But it wont show.
i tried smth like this:
RewriteRule ^([^-]*)-([^-]*)$ ./index.php?comp=$1&string=$2 [L]
How do i get it to work?
Do i have to make some changes in the php side as well?
everything what comes after the number part of the URL is there only for
SEO, the number is Unique
You need one more rule to handle two parameters:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(someserver\.com)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L,NE]
RewriteRule ^(\d+)/?$ index.php?comp=$1 [L,QSA]
RewriteRule ^(\d+)-(.+)/?$ index.php?comp=$1&string=$2 [L,QSA]
Related
my problem is that I want to get three simple rules working, but my knowledge is too little, to get them working together:
These are obvious:
RewriteRule ^login$ /login.php [L]
RewriteRule ^register$ /register.php [L]
domain.com/login and domain.com/register
Secondly, since i have only one page used for displaying data, i want its url to be as simple as posible, like:
RewriteRule ^(.*)$ /data.php?id=$1 [L]
which should be translated into:
domain.com/1a2s3d
As third, I want to be able to change url with activation code:
RewriteRule ^register/activate/([^/]+)$ /register.php?action=activate&code=$1 [L]
which finally should be translated into:
domain.com/register/activate/some-hash
I know just simply basics. And I cannot mix all of these three ideas into one single working htaccess file. With the second rule the server gives me 500 error, with third rule registration page works, but css file path is translated into domain.com/register/activate/theme/style.css instead of domain.com/theme/style.css
Any help would be appreciated.
Try just with that:
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^login$ /login.php [L]
RewriteRule ^register$ /register.php [L]
RewriteRule ^register/activate/([^/]+)$ /register.php?action=activate&code=$1 [L]
RewriteRule ^(.*)$ /data.php?id=$1 [L]
What am I doing wrong, here?
I've moved to a new Web store platform (OSCommerce to Drual/Ubercart). OSCommerce uses arguments to pick out products.
I want to redirect from this:
http://www.ztwistbooks.com/oscstore/product_info.php?products_id=64
To this:
http://www.ztwistbooks.com/node/39
This does NOT work (it gives a 404):
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^oscstore/product_info.php\?products_id\=64$ "http\://www.ztwistbooks.com/node/39" [R=302,L]
Other rewrite rules are fine, for instance, I can redirect stuff that doesn't use the ?arg=value, and it works fine:
RewriteCond %{HTTP_HOST} ^.$
RewriteRule ^oscstore/?(.)$ "http\://www.ztwistbooks.com/index.php" [R=301,L]
RewriteRule's pattern is applied to the URL-path, so you need something like this:
RewriteCond %{QUERY_STRING} ^products_id=64$
RewriteRule ^oscstore/product_info.php$ http://www.ztwistbooks.com/node/39 [R=302,L]
Im trying to redirect this,
example.com/slide?page=4 to example.com/slide/issue43?page=4
But it cannot effect other URL's like, example.com/slide/issue57?page=4
Im really stuck, these regular expressions are so weird. Here's the rewriterule that I've come up with,
This is not working
RewriteRule ^slide?page(.*)$ http://example.com/slide/issue43?page=$1 [L,R=301]
I need to target 'slide?page=X' specifically and have it redirect or point to 'slide/issue43?page=X'
This should work for you:
RewriteCond %{REQUEST_URI} ^/slide$
RewriteCond %{QUERY_STRING} ^page=(.*)$
RewriteRule ^(.*) /slide/issue57?page=%1 [R=301,L]
I've been looking, at all of the same questions in here like my own: How to rewrite multiple parameters? And figured how to do, but it doesn't seem to work out very well for me.
I wan't my link to look like this: link.dk/profil/2/overview
And my .htaccess looks like this:
#profil.php?id=? to profil/?
RewriteRule ^profil/(.*)$ profil.php?id=$1 [L]
RewriteRule ^profil/(.*)/(.*)$ profil.php?id=$1&do=$2 [L]
It has to be able to access /profil/2 without the 3rd parameter. That's why I have 2 lines. I don't know if this is the right way to do it.
/profil/2 is working perfect and has been working for a while now. So no worries here. But I can't catch the 3rd parameter.
I'm also having those 2 in .htaccess file:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Before the first two I wrote.
If I am using just the one with 2 parameters it's working. But then it's not working with /profil/2 ofc. And if I enter the url with profil.php?id=2&do=overview - I can access the page.
Found out my self:
RewriteRule ^profil/([^/]+)$ profil.php?id=$1
RewriteRule ^profil/([^/]+)/([a-z]+)$ profil.php?id=$1&do=$2
.* seems abit unprecise and unstable :-)
I want to have my site urls look like
http://example.com/place/info?var=info&morevars=ifneeded
Place and info are also variables but they have a fixed name, the ones after would vary. EDIT This is the url I am trying to rewrite
http://example.com/test.php?place=test&action=info&var=info&morevars=ifneeded
This is what I have so far
RewriteEngine on
RewriteRule ^([A-Za-z0-9-]+)/?$ test.php?place=$1 [NC]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ test.php?place=$1&action=$2 [NC]
I think there a way to do this with {QUERY_STRING} but I can't get it to work just 500 errors or it don't make a differences.
You have set the QSA flag that automatically appends the original requested query to the new one:
RewriteEngine on
RewriteRule ^([A-Za-z0-9-]+)/?$ test.php?place=$1 [NC,QSA]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ test.php?place=$1&action=$2 [NC,QSA]
You're missing the first /
RewriteEngine on
RewriteRule ^/([A-Za-z0-9-]+)/ test2.php?place=$1 [NC]
RewriteRule ^/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/ test2.php?place=$1&action=$2 [NC]