I need a simple redirect for my pages.
I need the following rewritten:
http://abc.de/application/index.cfm/fuseaction/home.uebersicht/idLand/44/idReiseart/268/web/Aktivreisen-Wanderreisen.htm http://abc.de/aktivreisen-schottland.html
http://abc.de/application/index.cfm/fuseaction/home.uebersicht/idLand/44/idReiseart/270/web/Busrundreisen.htm http://abc.de/busrundreisen-schottland.html
http://abc.de/application/index.cfm/fuseaction/home.uebersicht/idLand/44/idReiseart/1223/web/Ferienhotels.htm http://abc.de/hotels-schottland.html
http://abc.de/application/index.cfm/fuseaction/home.uebersicht/idLand/44/idReiseart/1217/web/Auto-Rundreisen.htm http://abc.de/auto-rundreisen-schottland.html
http://abc.de/application/index.cfm/fuseaction/home.uebersicht/idLand/44/idReiseart/1222/web/Stadthotels.htm http://abc.de/hotels-schottland.html
http://abc.de/application/index.cfm/fuseaction/home.uebersicht/idLand/44/idReiseart/1212/web/Unterkunftsschecks.htm http://abc.de/unterkunftsschecks-schottland.html
The problem is that /application/index.cfm does not exist and the server displays a 404 not found irrespective of how I configure http.conf or the .htaccess file.
What should I put in my .htaccess file?
Based on the example above you'd need to rewrite each one individually. The reason is that there is no repeatable mapping pattern between the .htm pages and the ones you're rewriting to:
Rewrite Engine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule application/index.cfm/fuseaction/home.uebersicht/idLand/44/idReiseart/268/web/Aktivreisen-Wanderreisen.htm http://abc.de/aktivreisen-schottland.html [NC,R=301]
RewriteRule application/index.cfm/fuseaction/home.uebersicht/idLand/44/idReiseart/270/web/Busrundreisen.htm http://abc.de/busrundreisen-schottland.html [NC,R=301]
RewriteRule application/index.cfm/fuseaction/home.uebersicht/idLand/44/idReiseart/1223/web/Ferienhotels.htm http://abc.de/hotels-schottland.html [NC,R=301]
RewriteRule application/index.cfm/fuseaction/home.uebersicht/idLand/44/idReiseart/1217/web/Auto-Rundreisen.htm http://abc.de/auto-rundreisen-schottland.html [NC,R=301]
RewriteRule application/index.cfm/fuseaction/home.uebersicht/idLand/44/idReiseart/1222/web/Stadthotels.htm http://abc.de/hotels-schottland.html [NC,R=301]
RewriteRule application/index.cfm/fuseaction/home.uebersicht/idLand/44/idReiseart/1212/web/Unterkunftsschecks.htm http://abc.de/unterkunftsschecks-schottland.html [NC,R=301]
Related
I know this is very common question but I can't seem find any solution regarding in my problem. The folder structure looks like this:
- rootProject
- subfolder
* .htaccess
* index.php
Normal url params: http://website.com/subfolder/?dynamicKey=dynamicValue.
But What I want to achieve is like this: http://website.com/subfolder/dynamicKey/dynamicValue
But I failed to do that, I can only retrieve the dynamicKey.
Here is my current htaccess:
RewriteEngine On
RewriteRule ^([a-z]+)/?$ index.php?$1 [NC,QSA,L]
Thanks to #Ar Rakin. Here is the solution.
RewriteEngine On
RewriteRule ^([a-z]+)/?$ index.php?$1 [NC,QSA,L]
RewriteRule ^([a-z]+)/([a-z]+)/?$ index.php?$1=$2 [NC,QSA,L]
With your shown samples and attempted code, please try following htaccess rules. We need to add conditional checks before rewrite rules else later it will affect your existing pages also.
Make sure to clear your browser cache before testing your URLs.
RewriteEngine On
##Added conditions if non-existing pages requested then only perform rewrite.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z]+)/?$ index.php?$1 [NC,QSA,L]
##Added conditions if non-existing pages requested then only perform rewrite.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z]+)/([a-z]+)/?$ index.php?$1=$2 [NC,QSA,L]
NOTE: your used regex [a-z] will only match small letters in uri, in case it needed to check any alphabets(capital OR small) then change FROM [a-z] TO [a-zA-Z] in above rules also.
I havve been using an htaccess file to create rewrites so as not to not have to include .php/.html filenames in my urls.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example-page.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example-page.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule /front /front_page.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule /redirect /redirect-page.php
However as my code is currently written the redirects are not working and all attempts at loading the pages with anything else besides the filenames is giving me a 404 error. How might i fix my code to get the redirecting to work?
Write the directives like this instead:
RewriteEngine on
RewriteRule ^front$ /front_page.php [L]
RewriteRule ^redirect$ /redirect-page.php [L]
There doesn't seem to be a need for all your additional conditions? I assume you only have the one domain example-page.com and you don't have a file called /front etc.
In .htaccess, the URL-path matched by the RewriteRule pattern does not start with a slash. You should also include start/end-of-string anchors on the regex so that you only match front exactly and not match it anywhere in the URL-path.
I'm working on a web application that requires using .htaccess for URL rewriting. I want to pass all request to a single file.
How can i use a single RewriteRule to achieve this?
This will work perfectly fine for you
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) /path/to/file [L]
The RewriteCond ensures the static files aren't rewritten (ie. robots.txt, favicon.ico, img/potato.jpg)
You can use a RewriteRule that always matches:
RewriteRule ^ /path/to/the/file [L]
You might want to add a RewriteCond as well. For example:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /app.php [L]
The RewriteCond ensures that urls that map to an actual static file in your web root do not get rewritten (ie. robots.txt, favicon.ico, img/potato.jpg )
I need to get the following URL rewrite syntax correct and am struggling.
xxxxx.com/public_html/food/
Needs to be rewritten as:
xxxxx.com/food/
I tried this and it doesn't work:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/public_html/food/(.*)$
RewriteRule ^(.*)$ http://xxxxx.com/food/%1 [R=301,L]
My client is using Joomla (which I am not familiar with), so I need to do so using the .htaccess file per everything I have researched so far. I am just struggling getting the syntax to work correctly though.
Thanks!
Try this, .htaccess
for Rewrite
RewriteEngine On
RewriteRule ^food/?(.*)$ http://xxxxx.com/public_html/food/$1 [QSA,L]
for Redirect (add R=301)
RewriteEngine On
RewriteRule ^food/?(.*)$ http://xxxxx.com/public_html/food/$1 [R=301,QSA,L]
Edit:
If you want to rewrite all urls (including /food)
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public_html/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /public_html/$1 [QSA,L]
It will allow you to access site like,
http://xxxxx.com/food/ will point to http://xxxxx.com/public_html/food/
http://xxxxx.com/sample/ will point to http://xxxxx.com/public_html/sample/
http://xxxxx.com/anything/cool/?product=123 will point to http://xxxxx.com/public_html/anything/cool/?product=123/
I have reviewed multiple threads on this topic, but all of them are dealing with multiple parameters, and me being quite new with .htaccess I wasn't able to figure out how to modify the answers to fit what I need.
I am rewriting URLs using .htaccess and everything seems to be going well except when I tried rewriting the pagination URLs.
My pagination urls are quite simple: blog.php?page=2 but I cannot rewrite the url to /blog/page/2 for some reason. I get an "Internal Server Error" when I try to route it to that URL. Right now I have it rewritten to /blog-page/2 which is okay, but I would prefer to have it /blog/page/2.
I have a lot going on in my .htaccess file, so I'll only post the rewrites:
RewriteEngine On
# Full path
#RewriteBase /
# Rewrite all php files
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
# Rewrite the user profile pages
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^user/([a-zA-Z0-9_-]+)$ profile.php?user=$1
RewriteRule ^user/([a-zA-Z0-9_-]+)/$ profile.php?user=$1
# Rewrite the company profile pages
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^company/([a-zA-Z0-9_-]+)$ employer.php?user=$1
RewriteRule ^company/([a-zA-Z0-9_-]+)/$ employer.php?user=$1
# Rewrite the blog post pages
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^post/([a-zA-Z0-9_-]+)$ entry.php?id=$1
RewriteRule ^post/([a-zA-Z0-9_-]+)/$ entry.php?id=$1
# Rewrite the job listing pages
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^job/([a-zA-Z0-9_-]+)$ listing.php?id=$1
RewriteRule ^job/([a-zA-Z0-9_-]+)/$ listing.php?id=$1
# Rewrite blog pagination
RewriteRule ^blog/page/([0-9]+)$ blog.php?page=$1
RewriteRule ^blog/page/([0-9]+)/$ blog.php?page=$1
Obviously the problem I am having is with the final RewriteRule's for the blog pagination. Why is it that I cannot make it /blog/page/2 but I can make it /blog-page/2?
I am also trying to do a multiple page .htaccess rewrite for the blog categories and the job categories but I keep getting an internal error. I want 1 rewrite for blog the job categories and the blog categories. Here is what I have for that:
# Rewrite the category queries
RewriteRule ^/category/(.*)/?$ /$.php?cat=$1 [L,QSA]
Is it possible to make this pagination rewrite work for 2 different pages? Such as blogs.php and jobs.php?
Also, is it necessary to keep putting the RewriteCond %{REQUEST_FILENAME} !-f before I make a rewrite rule? Or is 1 time sufficient?
Have you checked the apache error log for info on the error message? If not, that's the first place to start whenever you get a 500 internal error message.
Take a look at RewriteCond in the apache manual. It appears that you're expecting the RewriteCond to work for multiple rules, but that's not how it works. A RewriteCond only applies to the next RewriteRule. You can chain multiple RewriteCond lines together for a single RewriteRule but if you want a RewriteCond to apply to RewriteRules, you'd have to put it before each one.
The good news is most of your rules don't need a RewriteCond:
RewriteEngine On
# Rewrite all php files
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
# Rewrite the user profile pages
RewriteRule ^user/([a-zA-Z0-9_-]+)/?$ profile.php?user=$1 [L]
RewriteCond
# Rewrite the company profile pages
RewriteRule ^company/([a-zA-Z0-9_-]+)/?$ employer.php?user=$1 [L]
# Rewrite the blog post pages
RewriteRule ^post/([a-zA-Z0-9_-]+)/?$ entry.php?id=$1 [L]
# Rewrite the job listing pages
RewriteRule ^job/([a-zA-Z0-9_-]+)/?$ listing.php?id=$1 [L]
# Rewrite blog pagination
RewriteRule ^blog/page/([0-9]+)/?$ blog.php?page=$1 [L]
I made a few changes to your rules:
Removed most of the RewriteCond rules. If you plan to have some static files in any of the directories, you'll need to add the RewriteCond %{REQUEST_FILENAME} !-f rule for them to be served.
Consolidated the rules to handle the trailing / by adding a ? to make the slash optional.
Added [L] to your rules to indicate that no other rules need to be run after a match is found and executed. Take a look at RewriteRule in the apache manual for more details on the available flags.