Htaccess giving me too many redirects - php

I need help modifying my htaccess file. I have:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^phpbb3.*$ http://mydomain.com/phpbb3/ [R=301,L]
RewriteCond %{HTTP_HOST} mydomain.com$
RewriteCond %{REQUEST_URI} !^/wordit
RewriteRule ^(.*)$ http://www.mydomain.com/wordit/$1 [R=302,L]
Originally I only had:
RewriteCond %{HTTP_HOST} mydomain.com$
RewriteCond %{REQUEST_URI} !^/wordit
RewriteRule ^(.*)$ http://www.mydomain.com/wordit/$1 [R=302,L]
Which I need to keep. But I'm not sure how to incorporate the new rule:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^phpbb3.*$ http://mydomain.com/phpbb3/ [R=301,L]
How do I need to format my redirect?

I think this is what is happening: The rewritten URL coming out of your new rule actually matches the rule itself, so it just loops and loops and loops.
A very simple modification might work:
RewriteRule ^phpbb3[^/]+$ http://mydomain.com/phpbb3/ [R=301,L]

Related

Subdomain URL Redirect dynamically. .htaccess

I want redirect url using .htaccess
like.
abc.website.com to website.com/folder/abc
http://abc.website.com to http://www.website.com/folder/abc
using .htaccess from PHP server
Use below rule,
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www|webmail|help|whm|root)
RewriteCond %{HTTP_HOST} ^(.+?)\.website.com
RewriteRule ^ http://www.website.com/folder/%1 [R=301,L]
Try putting this in your .htaccess file:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^abc.website.com
RewriteRule ^(.*)$ http://website.com/folder/abc/$1 [L,NC,QSA]
For a more general rule (that works with any subdomain, not just sub) replace the last two lines with this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.abc.website\.com
RewriteRule ^(.*)$ http://website.com/folder/%1/$1 [L,NC,QSA]
I hope it will work for you.

How to pass multiple parameter in .htaccess

I have url that I want to rewrite so it can pass the parameter like this
From www.example.com/questions.php/postid=101&title=htaccess_tuts
To www.example.com/questions.php/postid/1/title/htaccess_tuts
I have been trying to get this done using below .htaccess but i end up getting this
From www.example.com/questions.php/postid=1&title=htaccess_tuts
To www.example.com/questions.php/postid/101
The title part didn't show.
Can anyone help me pass it multiple parameter
RewriteBase /
#Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
#here is the problem i have don this but didn't work
#RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+questions\.php\?postid=([^\s&]+)&([^\s&]+) [NC]
#What can i do again?
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+questions\.php\?postid=([^\s&]+) [NC]
RewriteRule ^ questions/%1? [R=301,L]
RewriteRule ^questions/([^/]+)/?$ questions.php?postid=$1&title=$2 [L,QSA]
RewriteEngine On
RewriteRule ^questions\.php/postid/([^/]*)/title/([^/]*)$ /questions.php?postid=$1&title=$2 [L]
you can use this site for generate rewrite rules

Mod Rewrite URL with several parameters

I'm currently having a hard time rewriting a URL. The .htaccess file already contains some rules so I need to add a new rule to the existing ones. The current rule includes redirecting to https:// if http:// was used (except if the URL contains 'php05142013'). Here's the current content of the .htaccess file:
ErrorDocument 404 https://mycreditstatus.co.za/404.php
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^mysite\.co\.za$ [NC]
RewriteCond %{REQUEST_URI} !^/(php01202015) [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www.mysite\.co\.za$ [NC]
RewriteCond %{REQUEST_URI} !^/(php01202015) [NC]
RewriteRule (.*) https://mycreditstatus.co.za [L,R=301]
What I want to achieve now in addition to the current rules, is to rewrite the URL like https://mysite.co.za/3pv/XnAnr3ABtgo%3D/3irqrHe%2FQJE%3D into https://mysite.co.za/index.php?action=register&auth=1&p=3pv&eid=XnAnr3ABtgo%3D&us=3irqrHe%2FQJE%3D
I've been trying something like ^/([^A-Za-z0-9.)(/\\%-])/([^A-Za-z0-9.)(/\\%-])/([^A-Za-z0-9.)(/\\%-])/([^A-Za-z0-9.)(/\\%-])/?$ index.php?action=register&auth=1&p=$1&eid=$2&us=$3&%{QUERY_STRING} [NC,L] # Process product requests and I'm sure it's wrong. I'm new to mod rewrite and I find it very confusing. Any help would be appreciated. Thanks.
You can use this new rule:
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ index.php?action=register&auth=1&p=$1&eid=$2&us=$3 [QSA,L]

htaccess RewriteEngine

I have an url which is http://www.urlbookmarking.com/bookmarks-details.php?bid=55
and I want it to be like
http://www.urlbookmarking.com/bookmark/55
I wrote in my htaccess:
RewriteEngine on
RewriteRule /bid/(.*) bookmarks-details.php?bid=$1
But when I go to the first URL the rewrite engine does not apply my rule. Is there any mistake, or conflict somewhere?
My full htaccess file written as follows
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteEngine on
RewriteCond %{HTTP_HOST} ^urlbookmarking.com [NC]
RewriteRule ^(.*)$ http://www.urlbookmarking.com/$1 [L,R=301]
RewriteEngine on
RewriteRule /bid/(.*) bookmarks-details.php?bid=$1
Please help me.
The line Options +FollowSymLinks is optional if already configured in httpd.conf
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^urlbookmarking\.com [NC]
RewriteRule ^(.*)$ http://www.urlbookmarking.com/$1 [R=301, L]
RewriteRule ^bookmark/([0-9]+)$ bookmarks-details.php?bid=$1 [NC, L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
A few things:
RewriteEngine On only needs to called once, though this may not be causing any problems
I also have RewriteBase / after my RewriteEngine On line
My rewrite rule looks like this: RewriteRule ^common/(.*)$ common.php?file=$1 [QSA,L], which tells me that your rule should looke like this RewriteRule ^bookmark/(.*) bookmarks-details.php?bid=$1 [QSA,L]
you should use only one RewriteEngine on
RewriteRule /bid/(.*) bookmarks-details.php?bid=$1 - put this line after Options +FollowSymLinks
Try again
Do you want you url to be /bid/55 or /bookmark/55? because you have written it as if it is going to be /bid/55...
Anyway, your .htaccess should look more like this:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^urlbookmarking.com [NC]
RewriteRule ^(.*)$ http://www.urlbookmarking.com/$1 [L,R=301]
RewriteRule ^bid/(.*)$ bookmarks-details.php?bid=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
...without the multiple RewriteEngine on directives (these don't break anything but are unnecessary), and without the leading forward slash on the bid rewrite rule. Also, put your new rule before the rules that rewrites for non-existent file so it doesn't rewrite your URL before you get a chance to use it, and add a [L] flag to the rule so it doesn't get further modified by the other rules. Also, add the line start/end markers (^/$) to the rule.
You would only use the leading forward slash if you were putting the rules in httpd.conf, you don't use them in .htaccess files.
If you want your urls to be /bookmark/, just replace bid with bookmark.
This should redirect all '/bookmarks-details.php\?bid=(id)' urls with bookmarks ids (that have only numbers) to /bookmark/(id).
RewriteRule ^/bookmarks-details\.php\?bid=([0-9]+) /bookmark/$1 [R, NC, L]
Once you successfully rewritten the URL, you then need to write a companion rule to process it, like so:
RewriteRule ^/bookmark/([0-9]+) /bookmarks-details\.php\?bid=$1 [NC, L]
If should go between the rule that always adds 'www' to the beginning and the catch all rule, which I placed at the end. All together, it may look like so:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^urlbookmarking.com [NC]
RewriteRule ^(.*)$ http://www.urlbookmarking.com/$1 [L,R=301]
RewriteRule ^/bookmarks-details\.php\?bid=([0-9]+) /bookmark/$1 [R, NC, L]
RewriteRule ^/bookmark/([0-9]+) /bookmarks-details\.php\?bid=$1 [NC, L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
This link may make things clearer: http://corz.org/serv/tricks/htaccess2.php

Simple htaccess rewrite/redirect to search page

I have a search form that sends a GET request to a page called search.php. I have rewrite rules set up in my htaccess file that rewrite certain things, like /search, to their respective pages. I simply want to take the search.php?q=query and rewrite it to /search/query.
Here is what I have.
RewriteRule search.php?q=(.*) /search/$1
RewriteRule search/(.*) search.php?q=$1 [nc]
What am I doing wrong?!
Here is the complete file
ErrorDocument 404 /index.php?p=404
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^images/.*\.jpg$ /images/default.jpg [L]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?wghandcrafted.com/.*$ [NC]
RewriteRule \.(gif|jpg|jpeg|psd|js|swf|flv|png)$ /feed/ [R=302]
RewriteRule ^(products|blog|feed|search|checkout|checkout)$ $1.php [nc]
RewriteRule products/cat/(.*)$ products.php?type=cat&cat=$1 [nc]
RewriteRule products/(.*)$ products.php?type=single&product=$1 [nc]
RewriteRule blog/(.*) blog.php&post=$1 [nc]
RewriteRule feed/(.*) feed.phptype=$1 [nc]
RewriteRule search\.php?q=(.*)$ /search/$1 [R=301,L]
RewriteRule search/(.*)$ search.php?q=$1 [NC]
Make the first line perform a Redirect and the second perform a Rewrite
RewriteRule search\.php?q=(.*)$ /search/$1 [R=301,L]
RewriteRule search/(.*)$ search.php?q=$1 [NC]
and move
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^images/.*\.jpg$ /images/default.jpg [L]
to the end of the set of rules.
Otherwise, the RewriteCond %{REQUEST_FILENAME} !-f rule is enacted before anything else, meaning that only requests for non-existant files will be handled by any rules below that line. As there is a search.php file, this prevents that rule from ever being reached.
I was having the same problem and here is a solution i found that worked for me, on my site the queries are being sent to index.php, I discovered if I had "^index.php$ /search/%1? [R=301]" as the first rewrite rule it will just error out because of the second rewrite rule making it just go in a loop so i replaced "^index.php$" with "^$" allowing it to still request the same file. It might not be the best solution, but a work around that works. Here is my working code:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^q=(.*)$
RewriteRule ^$ /search/%1? [R=301]
RewriteBase /search
RewriteRule ^search/(.*)$ /index.php?q=$1 [NC]

Categories