.htaccess remove part of url - apache

I´m not feeling good asking this question (there are already a lot of good answers + tuts here). But after hours of trial I need help.
THE PROBLEM:
Due to an CMS Migration URLs have changed a bit. Old URLs are safed in a Database. Before I change ever link in Mysql I thought it would be much faster to do an .htaccess rewrite of those links. What I want is:
change
index.php/aktuelles?id=369:netzwerk-forst-und-holz-unterfranken-startet-ab-12-2012-&catid=1:news
to
index.php/369:netzwerk-forst-und-holz-unterfranken-startet-ab-12-2012-&catid=1:news
means simple cut the
aktuelles?id=
of the URL. Here my trials:
RewriteEngine On
Options +FollowSymLinks
RewriteRule ^aktuelles\?id\=$ $1 [R=301]
#RewriteRule (.*)/index.php/aktuelles?id=(.*) $1/$2 [R=301]
Thanks a lot for your help,
kind regards,
tony

Here you go. This should cut out the aktuelles?id= from the provided URL:
RewriteCond %{QUERY_STRING} ^id=([^]+]+)$
RewriteRule ^([^/]*)/(aktuelles)$ $1/%1? [L, R=301]
It's untested - please tell me if this worked for you.

Related

.htaccess url parameter rewrite for specific page

I have been battling for hours now and searched Google and StackOverflow, without a solution to my problem, hope you guys can help! :-)
I have a page with parameters as follows: profile?userid=123456789. I want it to rewrite to profile/123456789. This I have, but now everywhere on this page all links gets /profile/link. Is there any fixes to this? Thanks in advance, here comes my .htaccess code.
RewriteEngine on
RewriteCond %{REQUEST_URI} !/profile\.php
RewriteRule ^profile/([^/]*)$ /profile?userid=$1 [L,QSA]
try this, it works for me with many configurations
RewriteEngine On
RewriteRule ^profile/([^/]*)$ /profile?id=$1 [L]
if you want the ([^/]*) to be exclusively number, you'll need to use PHP to rewrite your urls
You can change your rule parameter order as below to make it work
RewriteEngine on
RewriteRule ^profile?userid=([^/]*)$ profile/$1 [L]
Hope this will help you :)

mod_rewrite URL change with additional parameters

Struggling to get anything but simple rewrites to happen so I am hoping I can present a real example and get a sample so I can understand what I am doing wrong.
This is the existing URL:
http://127.0.0.1/reports/queue.php?status=all&frequency=all
Trying to change it to:
http://127.0.0.1/api/server/server.php?f=ReportQueue&selector=queue&status=all&frequency=all
What is interesting is I cant even "break" it to step through and see how my changes impact the rewrite. For example I would do:
RewriteRule ^reports/queue(.*)$ api/server/server.php$1 [R=301,NE,L]
I actually expected this to provide a page not found but it doesn't seem to do anything. I have verified that mod_rewrite is working by doing some more simple examples.
Any help would be appreciated.
Try :
RewriteEngine on
RewriteCond %{THE_REQUEST} /reports/queue\.php\?status=all&frequency=all [NC]
RewriteRule ^ /api/server/server.php?f=ReportQueue&selector=queue [L,QSA,R=302]

URL rewriting test for beginners

I was just learning to rewrite urls but got error on my first step.
My current url is:
http://localhost/tutorials/blog.php?blogId=30
.htaccess
RewriteEngine On
RewriteRule ^blogs/([0-9]+)/?$ blog.php?blogId=$1 [NC,L]
According to guide after this code my url should look like
http://localhost/tutorials/blogs/30/ but it's still same so where I am going wrong. Both .htaccess and blog.php are in same folder.
The code you have provides you an alternate way to work on URLs of the form http://localhost/tutorials/blogs/30/. It does not format the uglier URL to pretty/friendly one.
Use the following to achieve that:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET\ /(.*blog)\.php\?blogId=(\d+) [NC]
RewriteRule ^ /%1s/%2/? [R=301,L,NC]
RewriteRule ^blogs/([0-9]+)/?$ blog.php?blogId=$1 [NC,L]
URL rewriting can be one of the best and quickest ways to improve the usability and search friendliness of your site. It can also be the source of near-unending misery and suffering. Definitely worth playing carefully with it - lots of testing is recommended. With great power comes great responsibility, and all that.
Refer this article https://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/.

Apache .htaccess redirect URL directories containing parameters

Sorry to be the asker of yet another tedious mod_rewrite question but after having made no progress in the last few hours, I thought it was time to ask ;)
I am trying to redirect URLs like these:
/some/thing?a=1 --> http://something-else.com/blah
/some/thing?a=1&b=whatever --> http://something-else.com/blah2
No need to keep the param values - the new URL will be hard-coded for each one I have to be redirected.
Have tried a few different things from other posts but with no joy so I am back to square one so any suggestions would be most welcome.
Thanks! :)
You can use the following rule-set:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^a=1$
RewriteRule /some/thing http://something-else.com/blah [L]
This is indeed quite a common question, and people tend to overlook the QUERY_STRING variable. Have you tried it before?
This is what I used in the end:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(a=1&b=whatever)$
RewriteRule /some/thing http://something-else.com/blah2 [L,R=301]
I was adding the rules at the bottom rather than directly below the "RewriteEngine On" which was preventing it from working.
This solution does still append the params to http://something-else.com/blah2 which isn't exactly what I wanted but it will do.

Simple .htaccess subdomain rewrite

I know there is a lot of questions on here about this... but right now I feel like a deer stunned by oncoming headlights... I just don't know where to start and which option to choose.
My requirements are simple.
User goes to http://application.domain.com or http://www.application.domain.com and the real location of these files is http://www.domain.com/application
Obviously this needs to be done using wildcards so that any domain (even if it doesn't exist) triggers the rewrite.
I hope this makes sense to someone
EDIT:
I should also mention I have added the wildcard A record to my DNS entries in Cpanel *.domain.com
Thanks
Tim
I posted this question onto serverfault.com and icyrock solved it. Incase anyone else is wondering the answer given is here:
https://serverfault.com/questions/203780/troubleshooting-a-htaccess-wildcard-subdomain-rewrite/203804#203804
Tim
Simplest way in .htaccess would be to put the following in an htaccess file as high up in the hierarchy as possible.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.application\.* [OR]
RewriteCond %{HTTP_HOST} ^application\.* [NC]
RewriteRule .* http://www.domain.com/application [L]