I'm doing this to fix an error with my AMP pages. I'm using the Automatic AMP plugin, and this plugin lets you access the AMP pages using 2 different methods
site.com/post/amp/
site.com/post/?amp
Using the AMP Page validator (https://validator.ampproject.org) I see that all AMP pages using just /amp/ get multiple errors, while /?amp is validated correctly.
Unfortunately, Google is checking /amp/ for all my pages, hence I'm getting tons of errors.
What I'd like to know is how to use the .htaccess redirect rule to add the ? to the AMP queries so all /amp/ requests are redirected (with a 301) to /?amp/
I'd appreciate suggestions on this. Thank you
Something like this:
RewriteEngine on
RewriteRule ^(.*)/amp/$ /$1?amp [R=301,L]
This will redirect any URL ending in /amp/ to the same but with ?amp instead, which seems to be what you want. To go in your root .htaccess file.
Related
I would like to add a line to my htaccess to change this url:
RewriteEngine on
do this is the url
http://site/Calendar/viewevent?eventid=9223
into something like this :
http://site/Calendar/viewevent/Title-of-event
its php and joomla and I am a php developer, please dont advise me to use a component or module to handle redirects, I am trying to achieve this using .htaccess ONLY :) thank you in advance!!
Your 'pretty' url contains information that is not in the 'working' url. Besides that, the 'working' url also contains information that is not in the pretty url. You need database access to translate the event id to a seo-title, and the seo-title back to an event id. In other words: It is impossible to do this with .htaccess only, unless you change 'viewevent' to accept an event by seo-title, instead of eventid.
Mod_dbd can possible be used, but only in the server config file, not .htaccess.
As Sumurai8 says htaccess cant transform url like you want automatically.
But you can use Redirect 301 (or its variation) for one url to another.
for your example:
Redirect 301 /Calendar/viewevent?eventid=9223 /Calendar/viewevent/Title-of-event
more information here
I am currently administrating some art website that contains lots of photos and other content files and it bugs me that ppl find a way around scripting and are accessing stuff directly, they download our copyright protected materials.
I was thinking about htaccess file that do the following:
someone type in address directly to the browser: http://www.mydomain.com/photos/photo.jpg
htaccess triggers and instead of showing the content - it redirects right away to: http://www.mydomain.com/ (this is important to do redirect before picture is displayed)
redirect is extremely important not just some preventing without redirect, but if someone attempts to use sowftware to download content via providing link to it then it rejects request
my knowledge about htaccess is really thin i could use a help on this one
This should work:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://www.mydomain.com/ [NC]
RewriteRule .*\.jpg|gif$ /nolinking.html [R]
If you try enter http://www.mydomain.com/photos/photo.jpg it will redirect you to http://www.mydomain.com/nolinking.html, but it will allow images to be loaded on pages if they are linked to,
I want to rewrite pagination URLs http://mydomain.com/category?start=15 to http://mydomain.com/category/start/15, but I don't know how to achieve this with .htaccess.
PS: those URls ( http://mydomain.com/category?start=15) are referenced in search engines so I need to add 301 redirect to my new URLs.
I want mention that I already enabled SEF mode in Jommla configuration
First, if you want your URLs to look like /start/15 you have to rewrite them from the pretty format to the internal, not otherwise.
I currently have no access to an Apache, but your expression should look something simliar to this:
RewriteRule ^category/start/([0-9]+)$ http://mydomain.com/category?start=$1 [QSA,L]
Then, it would be neccesary to tell Joomla how to generate the pretty URLs, this happens without the htaccess file, for example in a SEO plugin.
Finally, to output 301 messages, you will want to add "Redirect" commands to your .htaccess file. Redirect incoming ?start=15 URLs to the pretty format. Make sure that this does not happen after your Rewrite...
I've tried many options in .htaccess without success. What I want to do is this:
I have Wordpress residing in its own folder, like this: site.com/folder
I want all users visiting site.com to be redirected to site.com/folder/page but in such a way that the URL doesn't change in the browser. All other URLs, such as site.com/folder and site.com/folder/page1 etc shouldn't be affected.
How to do this, in as SEO-friendly way as possible?
Thanks everyone.
You can't redirect a user to a other page from serverside without to show this to the use.
But if you need, you can use the HTML tag <frame> http://www.w3schools.com/tags/tag_frame.asp
But the bad side with this is the use always will be show "site.com" and not the real page.
But I think the best way is to proxy the result, in Apache you can do this by something like this.
RewriteEngine ON
RewriteRule ^/$ folder/page/index.php [L]
My site has more than 500 dynamic pages and i have make all static (same) pages and redirect old url or new url by using the following rule in htaccess file:
RewriteCond %{QUERY_STRING} ^cid=2&gas=nitrogen$
RewriteRule ^purity\.php$ http://Example.com/gases/nitrogen.php? [R=301,L]
and by using this code for all my pages are now static url's
and now i want to make it http://www.Example.com/gases/nitrogen (without extension) and for this i have uploaded the rule which is :
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^\ ]+)\.php\ [NC]
RewriteRule ^ /%1 [R=301]
This code is actually redirecting my php page to non php page but with 404 error.
Im unable to figure out the problem in this.
Pls help!!
There is a problem with what you are trying to do. You have to understand how rewrites work. You're making your webserver serve up a different page that doesn't exist. So by sending an ugly url to a better SEO'd one, you're saying ok server give me this page instead. If the page itself doesn't exist, then the server spits up a 404 error. Your rewrite should be from the page you want them to go to redirects to your old page name without the [R] parameter so your server knows, don't give this page, give that other page, and don't let them know it's being done by displaying that other url, that's what removing the [R] does. Then to prevent the endless redirect loop, don't redirect the ugly page name to the new one. Instead, simply display the redirected url instead of the ugly one with all those ugly looking parameters. however since you've probably already been indexed and search engines know about the ugly pages, I would recommend not only not linking to those pages anymore and use the new page names on all your pages for things like navigation, and referencing other pages, but I would add the canonical meta tag on your pages telling Google and other search engines what your preferred url is. If you had started out without any search engines knowing your url structure with all those parameters you could have skipped using the canonical meta tag as the search engines wouldn't know your pages by those names if you always used a rewrite.