Tag Info

Hot answers tagged

8

For your first two rewrites (non-www → www, http → https), the following rule should work: RewriteEngine On RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} !=www.example.com [NC] RewriteRule ^(.*) https://www.example.com/$1 [NS,L,R=permanent] Just replace www.example.com with the actual canonical hostname of your site. As for your third ...


6

The way that you will do the 301 redirect does not play any role for the Google. Actually it does not see your configuration file. What it is important is to send the 301 headers with the new location on each old url and not just the home page. For example if you have 10 pages on the old website, make sure that these all pages are redirected to the new 10 ...


5

Just redirect by 301 HTTP status all your old URLs to the new ones. If you only change file extension, you can do it easily with an .htaccess file (if you use Apache as a web server). Put these lines in your .htaccess file: RedirectMatch 301 (.*)\.html$ http://www.example.com$1.php Of course, change www.example.com by your domain name. By using 301 ...


4

You can use one of these solutions: Keep the Current .html extension unchanged for just frontend purpose and use Apache .htaccess file to proxify your requests so that. Add this to your .htaccess file to work: RewriteEngine on RewriteRule ^(.*).html $1.php OR Why not just have the HTML pages parsed as PHP? That way you can get the best of ...


3

The pseudo-code translation of your .htaccess file would be something along these lines: Line 1: In case we weren't previously planning to do anything special with URLs, we are now (RewriteEngine is an optional processing module and we're making sure its enabled). Line 2: When we're talking about rewrite URLs, from here on append the path /, which in your ...


3

You have RewriteEngine On missing RewriteCond are only applicable to next immediate RewriteRule Try this code: RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-l RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^explore/(.*)$ index.php?page=explore&type=$1 [L] RewriteCond %{REQUEST_FILENAME} !-l ...


3

You need to enable the rewrite engine in your .htaccess file if you have not done already... RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC] RewriteRule ^(.*)$ http://example.com/$1 [L,R=301] Note that I've removed the extra .com on the RewriteCond line that you have in your question - I'm assuming this was a typo? Also, FollowSymLinks ...


2

You need mod_alias, not mod_rewrite: Alias /zf2/ ../zf2/public Maybe you'll need to specify absolute path instead of relative. Another solution would be use of a filesystem symbolic link named zf2, placed in Project/public and pointing to ../zf2/public. In both cases you'll need Options +FollowSymlinks. And be careful about restrictions and where they ...


2

Does purposely and permanently having invalid URLs on your site that get 301'ed to the correct ones have any effect on SEO? I could make it just show the correct URL to begin with, but this is a significant amount of work due to how I am handling the translations, so I would prefer just to 301 them. Arguably, yes. According to Google, a 301 ...


2

RewriteCond %{HTTP_HOST} ^tech\.doig\.com\.au$ [NC] RewriteRule . - [S=120] You appear to be Skipping all of the relevant redirects when the HOST matches tech.doig.com.au, which would seem to be the opposite of what you are trying to achieve. As it stands, your redirect would only occur when the domain is not tech.doig.com.au. It looks like your ...


2

If you are changing an existing URL structure then you will need to redirect the old (ugly) URLs to the new (pretty) URLs, rather than reject them with a 403 response. If it's a brand new site then you could reject them with a 404 (R=404) - preferable to a 403 I think in this instance. Something like the following (placed before your existing rewrites): ...


2

As mentioned in comments above, you'll need a RewriteCond directive in order to prevent an internal rewrite loop. Whilst the L flag terminates the current rule set, the entire process is started again with the rewritten URL, so we need a get-out clause. RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{QUERY_STRING} !^fid= RewriteRule ...


2

You just need to change the URL structure in the same two lines: RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC] RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]


2

Yes that's correct and would 301 redirect everything on oldsite.org to the same path on http://newsite.com. Plenty of similar questions on the StackExchange network such as this one.


2

Triying the same and on my search I found that symfony2 frameworks .htaccess file is doing that at least it is stated in the file that it would. I tried to use it in my own setup but didnt work. Maybe that will help you guys somehow. # Determine the RewriteBase automatically and set it as environment variable. # If you are using Apache aliases to do mass ...


2

Either all Options must start with + or -, or no Option may. Ah yes! This behaviour has changed with the move to Apache 2.4 - it has always been invalid - but now "will be rejected during server startup by the syntax check with an abort." Reference: Apache Docs You need to specify a + before the Indexes option: Options +Indexes +FollowSymLinks ...


2

Your are planning on implementing a type of "reverse proxy" in PHP. There is an Apache module that does this already: mod_proxy You might find it easier to configure mod_proxy as a reverse proxy on your client's server rather than use PHP. mod_proxy can even be activated through rewrite rules for specific pages or directories: RewriteEngine On ...


2

You need to change your Redirect (mod_alias) to RewriteRule (mod_rewrite). Something like: RewriteRule ^word1/word2/word3 /word1/word2 [R=301,L] (Put back example/ if you wish, but it looked like a typo to me?) The problem you are experiencing is that mod_rewrite (nearly) always executes before mod_alias, regardless of the order of directives in your ...


2

It looks to me like you would are trying to fetch data from a web service that is running on another port and display it using your main web server. mod_rewrite can be configured to do so. You have to have mod_proxy enabled and use [P] with your rewrite rules. Your directives might look like this: RewriteEngine on RewriteCond %{HTTP_HOST} ...


2

You need to add "RewriteOptions Inherit" to each virtual server. See http://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#rewriteoptions for details.


2

You can use these three rewrite rules which handle up to 3 levels of directories: RewriteEngine on RewriteRule ^main\/([^\/]+)\/([^\/]+)\/([^\/]+)\/? /parser.php?var1=$1&var2=$2&var3=$3 [L] RewriteRule ^main\/([^\/]+)\/([^\/]+)\/? /parser.php?var1=$1&var2=$2 [L] RewriteRule ^main\/([^\/]+)\/? /parser.php?var1=$1 [L] In those regular ...


2

Your root .htaccess should look like this: # Mod RewriteRules, some 12 in all RewriteRule ^mod/(.*)$ /moderator/$1 [NC,L] RewriteRule ^signup/(.*)$ /acc/signup/$1 [NC,L] RewriteRule ^signin/(.*)$ /acc/signin/$1 [NC,L] RewriteRule ^signout/(.*)$ /acc/signout/$1 [NC,L] # These are the only two that a front end user will use # category/subCategory ...


2

I suspect you are over thinking this. I am really confused over all your code. One of the things I am finding these days is that people are using example code that is already unnecessarily complicated. As well, people seem to select {???} that offers too much instead of the narrowest selection. Often these things only require 2 lines or 3 at the most and ...


2

The type of redirect you are using is not the problem. 301 redirects are cacheable. In fact they are extremely hard to cache bust. 301 means "permanent" and browsers are very likely to cache 301 redirects with no way with the server to undo one that is already cached. 302 redirects are generally not cached by default unless other headers indicate that ...


2

I asked this same question on StackOverflow. To get it to work properly, you have to use environment variables: RewriteRule ^page$ /page.html [L,E=LOOP:1] RewriteCond %{ENV:REDIRECT_LOOP} !1 RewriteRule ^page.html$ /page [R=301,L] This is because mod_rewrite does multiple passes through your rules. During the first pass, it sets the environment ...


2

The problem is that, when you use mod_rewrite in an .htaccess file or a <Directory> section, every successful RewriteRule — even an internal one — causes the request to be restarted internally, and thus the whole rewrite ruleset to be reprocessed. Thus, what's happening is that, when the user visits /page, your internal RewriteRule matches ...


2

For Q1, the - doesn't mean that processing or iteration would be stopped, simply that the URL path would be passed through without any filtering or processing. The file will continue to execute rules until it reaches the end of the file or a rule is met that has the [L] last rule flag appended to it. To clarify then, RewriteRule .* - ...


1

Best way to do this is not from your .conf file. Do this: .htaccess example: RewriteEngine on RewriteCond %{REMOTE_ADDR} !^192\.168\.1\.1 #Replace with IP address you wish to allow RewriteRule .* http://www.yourwebsite.com [R=301,L] #Replace webaddress with yours Make this file in the directories you are trying to keep people out of. Then ...


1

It came down to the ssl .conf file being in the location that should have had a soft link to the file that I was editing. As soon as I fixed the link, the redirect start working. However, the logging wasn't working because I hadn't specified the RewriteLogLevel. I"m not sure if the level has to be specified, or if the default is 0 and as a result nothing ...



Only top voted, non community-wiki answers of a minimum length are eligible