Hot answers tagged mod-rewrite
5
I will go onto something like that.
First you define a new condition (RewriteCond) then you apply this condition using a rule (RewriteRule).
Thanks to the flag L at the end of the RewriteRule, this stop the rewriting process immediately and don't apply any more rules. So when the request is a .css file, the first rule will be apply and not the second one. ...
4
Finally realised what the problem was when, after deleting the tag in both files, the error "Invalid command '\xef\xbb\xbf
EF BB BF = BOM
Moral of the story: Always check your encoding* and hex dump of your files when you get weird issues.
*On Notepad++ you can use the Encoding -> Encode in UTF-8 without BOM option to remove it
3
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{QUERY_STRING} ^feed=podcast$
RewriteRule ^(.*)$ /feed/podcast [R=301,L]
This works because everything after the ? is the query string, and this rule takes effect when there is a question mark with feed=podcast after it.
3
You need to remove the carats from your RewriteCond lines:
RewriteBase /
RewriteCond %{THE_REQUEST} !subdir/.*\-new\-name\.html
RewriteRule ^subdir/(.*)\.html$ http://www.domain.tld/subdir/$1\-new\-name\.html [R=301,NC]
The rewrite conditions will then take effect and you'll avoid the infinite redirect loop. This is required because your old rewrite ...
3
Assuming you want a 301 (Moved Permanently) redirect, then put the following in the .htaccess file in your document root:
Options +FollowSymLinks # Must be enabled if not already
RewriteEngine On
RewriteRule ^abc/content/content\.jsp\?contentId=(123|345)$ https://newpage.silkroad.com/ [R=301,L]
3
You CAN check for the existence of a resource identified by an HTTP URL using mod_rewrite
See example below:
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteCond %{REQUEST_URI} ![.]html$
RewriteCond %{REQUEST_URI} ^([^.]*)
RewriteCond %1.html -U
RewriteRule ^.*$ $0.html ...
3
If you are using Wordpress now, and simply trying to redirect old Joomla urls to your new urls I suggest using a plugin to make your life easier.
I recommend this plugin a lot:
http://wordpress.org/extend/plugins/redirection/
Also keep in mind that you should use fancy permalinks within Wordpress instead of the standard ID numbers. You can find this ...
2
I ran into this issue a few weeks ago. Even with mods to my .htaccess file, I was never able to accomplish the rewrite with a site being hosted on GoDaddy. They have a 'manual' way of doing it through their Control Panel which ended up working for me.
http://support.godaddy.com/help/article/5120/redirect-urls-with-your-hosting-account
As far as I'm ...
2
Not guaranteed this is it, but try removing a line at a time until the error stops. That'll help you see which particular bit is causing the problem.
Getting a 500 from htaccess is sometimes a sign you're trying to do something you're not allowed to. Is mod_rewrite actually enabled, for example? The same for the Options line; If the server isn't configured ...
2
You should not do this, use Apache deflate module to Gzip you files. This is what I use in .htaccess :
<IfModule deflate_module>
AddOutputFilterByType DEFLATE text/php text/html text/txt text/javascript text/css application/javascript application/x-javascript
</IfModule>
Check out the documentation to have more info on the mime type ...
2
first, your redirect is in an infinite loop because of the question mark after -cars/?
cars/?(.*)
the question mark operator means optional, in that there may or may not be a slash after -cars. So lets say your old url is /vehicles-cars/23. With the rule as you have it, /vehicles-cars/23 matches, and redirects to vehicles-cars-for-sale/23 and the page ...
2
Various causes are possible here. It would be helpful to know more about your setup (folder layout, virtual host configuration and especially any other contents of your .htaccess files). Some things that come to my mind:
As Eric Brandel points out, mod_rewrite will apply all rules present in your .htaccess file (or server config) one by one unless [L] is ...
2
With .htaccess, if a request matches multiple rules, it will utilize the last one found, unless you tell it to stop processing. You can do that with adding [PT,L] to the end of each line.
# Rewrite rule for tags
RewriteRule ^tags/(\w+)/(\d+)/?$ restAPI.php?type=tags&tag_name=$1&tag_id=$2 [PT,L]
RewriteRule ^tags/(\w+)/?$ ...
2
Do you actually have a * wildcard record in your DNS zone file? If yes then all you need to do is add an A record into the zone file and point it to the IP hosting your domain.ca now all connections to that specific sub domain will go to www.domain.com while the other wildcard subdomains will go some place else.
Or in cPanel you would simply create your ...
2
You shouldn't need to use percent encoding/hexcode in mod_rewrite parameters since mod_rewrite will encode special characters (?, #, , &, etc.) by default. To write a space in the rewrite pattern, use \s or just escape the space with a backslash (\). Whether space gets encoded as %20 or + depends on whether it's part of the query string or the URI.
So ...
2
A few years ago, buying keyword rich domains and putting content on them was a good strategy. Google's algorithm really seemed to favor sites that had keywords in the domain name. There was some speculation as to whether this was caused by Google using keywords in the domain as a strong signal on its own, or whether these sites got so many links with ...
2
Your regular expression has the following problems:
It only has .* for the "site" and "sectionname", but is missing one for the "categoryname". Based on your example, there should be a third directory level in your regex.
You have parenthesis around items which you don't need to reference, but no parenthesis around the ID, which you will need to ...
2
You can put a rewrite rule like this in place in the .htaccess file. In this example "example.com" is the domain name and "subdirectory" is the name of the folder for which you want to remove the "www".
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^subdirectory(\/.*)?$ http://example.com/subdirectory$1 [R=301,L]
2
This should work for files of any extension:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^/(.*\..*)$
RewriteRule ^index\.php$ http://www.newsite.com/%1? [L,R=301]
Or to redirect the entire path and file request:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^/(.*)(\..*)$
RewriteRule ^index\.php$ http://www.newsite.com/%1%2? [L,R=301]
1
You could always use Disallow: /cookies in a robots.txt based on the user agent?
Or if you must drop a cookie to the crawlers, as described above by initall, to delete a cookie, simply have it expire immediately by setting expire to some time before the current time.
If you specified a domain and path for the cookie, you have to do the same when you ...
1
Try something like this:
RewriteCond %{HTTPS} ^on$
RewriteCond %{HTTP_HOST} ^www\.x\.co\.uk$
RewriteRule ^(.*)$ https://x\.co\.uk$1 [L,R=301]
This is redirect someone from https://www.x.co.uk to https://x.co.uk and not do anything if they are no on https.
1
First, redirect /login to https /login/code
RewriteRule ^login/?$ https://%{HTTP_HOST}/login/code [R=301,L]
You can also force /login/code to redirect to https in case the type in http /login/code:
RewriteCond %{HTTPS} ^off$
RewriteRule ^login/code$ https://%{HTTP_HOST}/login/code [R=301,L]
Then, you can rewrite /login/code
RewriteRule ^login/code$ ...
1
Short answer: No, it's not possible to setup wildcard subdomains with .htaccess.
To achieve what you want to do, you need to have a wildcard record in your DNS zone file, because your nameserver is where the subdomains are looked up. Also, many hosting companies will not allow you to add a wildcard record, so you'll have to check with them.
1
I found my way through my issue. As suggested by Eric Brandel I just made a rule with hard coded values for tag_name and tag_id as
RewriteRule ^test/(\w+)/(\d+)/?$ tags.php?tag_name=extra&tag_id=4
And I was able to get my Query parameters then I changes my RewriteRules to
# Rewrite rule for tags
RewriteRule ^tag/(\w+)/(\d+)/?$ ...
1
cPanel is not inherently involved here, by the way.
Do you actually know if you're allowed to do this? Not all hosts allow such config changes via .htaccess. You should probably contact support to check.
If you already know it's possible, you can add:
RewriteEngine On
to your .htaccess file. Just put it near the top so it's before any rewrite rules.
1
Just a little information. Best practices indicate that trafic from http has to be redirected to https. If your site is reachable on https, no more need to http.
I think you can associate no-www redirection to www with http redirection to https.
Moreover, be careful of duplicate content if your site is reachable with http and https.
1
Redirecting the homepage is never best practice. A "proper" homepage with a link to the second page is a better structure and gives you two pages now for targeting to search engines for different terms. It also allows search engines to better understand what your site is about.
If you wanted to redirect the second page back to the homepage that is not an ...
1
Yes, crawlers will recognise, crawl and index your rewritten links as long as they are included throughout your site. You should ensure that only the re-written links are included in the source and not the non-rewritten links.
You could improve the optimisation of these links further by including the article title as part of the URL.
No problem with ...
1
You can Get/Detect/check for existance of cookie through RewriteCond %{HTTP_COOKIE}
Set Cookie value with the RewriteRule flag cookie|CO which has this syntax:
[CO=NAME:VALUE:DOMAIN:lifetime:path:secure:httponly]
An example with them both together:
RewriteCond %{HTTP_COOKIE} cookiekey=cookievalue [NC]
RewriteRule ^(.*)$ /$1 ...
1
You can use a 301 redirect in your htaccess which is the most appropriate to denote that something has moved (mostly search engine wise).
Just put a line like this in the drupal .htaccess or even create a separate .htaccess in the folder you user (if you still have it)
redirect 301 /your_folder http://www.yourdomain.com/
What I usually do with drupal ...
Only top voted, non community-wiki answers of a minimum length are eligible

