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 :-)
Related
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]
I moved from a wordpress to a typo3 site. On my old sites, the links looked like this:
http://www.example.org/?page_id=44
now I want to redirect it to:
http://www.example.org/contact
Usually the redirects-rules are no problem, but this time I don't get it why it is not working:
I tried this:
Redirect 301 /?page_id=44 http://www.example.org/contact
as well as this:
RewriteRule http://www.example.org/\?page_id=44 http://www.example.org/contact [R=301,L]
and this here:
RewriteCond %{REQUEST_URI} ^example.org/\?page_id=44
RewriteRule ^(.*)$ http://www.example.org/contact [R=301,L]
Tried it in several browsers and incognito-mode, but it still remains wrong, it still adds the parameter instead of redirecting to the certain page.
I guess it is somehow doable with %{query_STRING} ?
Is it due to the param-thingy?
Any ideas how to solve this problem?
Okay, got it. It had something to do with the query string:
Final result:
RewriteCond %{QUERY_STRING} ^page_id=14$ [NC]
RewriteRule ^(index\.php){0,1}$ /kontakt/? [L,R=301,NC]
You can use:
RewriteCond %{THE_REQUEST} /\?page_id=44\s [NC]
RewriteRule ^/?$ /contact? [R=301,L]
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]
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 would like to redirect the page www.mysite.com/index.php to www.mysite.com/ to prevent duplicate content issues but that causes the problem that I can't login backend because this redirects http://www.example.com/administrator/index.php to http://www.example.com/administrator/ . I am using the following
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.(html?|php)\ HTTP/
RewriteRule (([^/]+/)*)index\.(html?|php)$ http://www.example.com/$1 [R=301,L]
but I have had to comment it out to login. Please can anyone show me where am I going wrong?
*I found a post for a similar but not identical problem suggesting
RewriteCond %{REQUEST_URI} !^/administrator could go in the middle, would that be right? Sorry, new to all this :)
Yes, you want your enter chain to look like this:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.(html?|php)\ HTTP/
RewriteCond %{REQUEST_URI} !^/administrator/
RewriteRule (([^/]+/)*)index\.(html?|php)$ http://www.example.com/$1 [R=301,L]
You pretty much got it right. Each of the RewriteCond conditions are inherently ANDed together and applied to the first RewriteRule after them. You can have the two RewriteCond in either order and both must be met in order for the rule to be applied.