In order to convert dynamic URLs on my site www.kitesmovie.co.in to static urls. Eg: www.kitesmovie.co.in/stories.php?id=10 to www.kitesmovie.co.in/Barbara_Mori_Hrithik_Roshan_New_Movie.
I tried using rewriting rules in my htaccess files, but it did not work. Please tell me how to do this.
Thanks a lot in advance.
It's not really clear what you are trying to achieve.
When you say "convert dynamic urls to static urls", do you really want to have user to type in the ...?id=10 and the file named Barbara_Mori_Hrithik_Roshan_New_Movie lives on your server? I think, it's the opposite way - you want to let the user type in the long & nice title and actually resolve it to ?id=10
If this is the case, the #Mike's answer is nearly correct, you only have to swap the parts of the last line:
RewriteRule Barbara_Mori_Hrithik_Roshan_New_Movie stories.php?id=10 [R,L]
Another question - are you sure you have the .htaccess working? An easy way to check is to set the contents of .htaccess to
order deny, allow
deny from all
And see if you can still access that directory. If you can, this means the "deny from all" does not work. Then check your apache config - is .htaccess allowed in the particular virtualhost and/or directory.
Lots of missing info there. If you are using apache with mod_rewite installed, place this in your .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule stories.php?id=10 Barbara_Mori_Hrithik_Roshan_New_Movie [R,L]
</IfModule>
You might want to have a look at this article: http://www.addedbytes.com/for-beginners/url-rewriting-for-beginners/
Generally, you would use a RewriteRule something like this:
RewriteRule ^stories.php?id=10$ Barbara_Mori_Hrithik_Roshan_New_Movie [R=301,L]
If that's not working for you, then feel free to add more details to your question.
Related
I have read a lot on stack about rewriterule and how it applies and I've tried reading up on some good articles online but I still cannot wrap my head around a few things.
I have blogs setup where all folders are in
https://domain.ca/posts/post-tree/*
So I've setup htaccess like this
RewriteRule ^posts/post-tree/(.*)$ /index.php?$1 [R=301]
As I'm sure you can guess this basically brings me root index.php where I catch this request with a $_GET to know the name of the blog folder it was requesting.
This is fine I can hit index.php and with $_GET I know the blog page they requested.
What I do not get, and I've tried a lot of things, is once I have this request in index.php how do I re-write the URL to show something like https://domain.ca/blogpage/ instead of looking like https://domain.ca/index.php? where https://domain.ca/blogpage/ does not really exist of course, but it is because I want to hide the http://domain.ca/posts/post-tree/ path.
Its a little like when wordpress processes a blog page with the id and after rewrites the url to whatever slug is set for that blog page. at least my understanding of it as they don't have individual folders for blogs, but I do.
I finally got this working with the following in the htaccess file
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
# the above checks if file or folder exists, if not the below is processed
# this will route to base index file and fetch $1 folder via $_GET
RewriteRule . /posts/post-tree/index.php?$1
I had turned Use URL rewriting to ON
Added some code in to the ht access file and this never worked.
I then turned off url rewriting and removed the code and now when I try to go to the website I am getting a 404 error.
I can still access /administration
the website is www2.daxtra.com
the page it should find is http://www2.daxtra.com/index.php/home
Does anyone have any ideas what has happened?
This was the code I added:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
Thanks
Right, I've done a small test.
To get what you want, you need to following:
htaccess.txt (you don't need a .htaccess file)
Search Engine Friendly URLs set to On
Use URL rewriting set to Off
You finally need to ensure that your Homepage menu items it set to a specific component such as an article or something else, not an Alias
This will ensure that you get example.com/index.php/home
Hope this helps
I think I'm misunderstanding some fundamental thing here, as this is my first time using mod_rewrite.
I would like the following:
blog.example.com
blog.example.com/
blog.example.com/index.php
to redirect to:
example.com/blog
However, I would like all other cases to do nothing, e.g.
blog.example.com/foobar
blog.example.com/wp-admin
blog.example.com/wp-admin.php
This is my current .htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} =blog.example.com
RewriteCond %{REQUEST_URI} ^|/|index\.php$
RewriteRule ^(.*)$ http://www\.example\.com/blog [QSA,L]
I have tried many variants but each time either all requests redirect, or none redirect, so mod_rewrite is definitely doing something, just not what I want.
I have skimmed through this post for anything relevant, but I think the issue is more that I'm missing some subtle fact due to inexperience. Would someone kindly point out my error? I know we don't need yet another mod_rewrite question on SO but I'm really struggling with this one. Thanks in advance.
Try this:
RewriteEngine On
RewriteCond %{HTTP_HOST} =blog.example.com [NC]
RewriteRule ^/?(index\.php)?$ http://www.example.com/blog [QSA,R,L]
Some basic points:
The second part of the rewrite rule is not a regular expression, so periods do not need to be escaped there.
I was not familiar with the =String option for RewriteCond. Thank you for teaching me something today (I was worried when I did not see a regex there but that should be fine)! I would add [NC] here since it will help match both lowercase and uppercase versions of your domain.
None of this will work unless your virtual host includes the blog.example.com subdomain as a proper alias, and DNS is set up for that subdomain.
I have a website build on jQuery scrollTo plugin. Each page is accessible via anchor's, ie.
www.domain.com/#page-one
and deeper
www.domain.com/#page-one--some-content.
I'd like to create rule with mod_rewrite so address like
www.domain.com/page-one
or
www.domain.com/page-one/some-content
point to the above one. Its quite easy with [R=301] flag but I need my "clean" address /page-one/some-content to stay in address bar not changing to #page-one--some-content.
Why I need to change them? Because for some reasons I need to use alternative site for MSIE and Opera, kind of regular one with reloading every page. I need the same links for both sites which is obvious, I think.
I spent lots of time digging & reading about anchors in URL's and stuff, but I haven't reach my goal. If any one can help me, I'll appreciate!
Thanks, Kuba.
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule (.*) /index.php#$1 [NE]
This works excellent for me.
I would like to rewrite /anything.anyextension into /?post=anything.
eg:
/this-is-a-post.php into /?post=this-is-a-post or
/this-is-a-post.html into /?post=this-is-a-post or even
/this-is-a-post/ into /?post=this-is-a-post
I tried
RewriteRule ^([a-zA-Z0-9_-]+)(|/|\.[a-z]{3,4})$ ?$1 [L]
but it doesn't work.
Any help appreciated.
If you have access to the main server configuration, use this:
RewriteRule ^/(.+)\.\w+$ /?post=\1 [L]
If not, and you are forced to put this in a .htaccess file, you could try
RewriteRule ^(.+)\.\w+$ /?post=\1 [L]
In either case, this assumes you will only be rewriting URLs with a single path component (i.e. if you get a request like /path/anything.anyextension it might not work as you expect, the rewrite rule would need to be modified to handle that)
You need a better way to determine when to apply the rewrite rule, otherwise your page won't be able to display external JS or CSS, unless you define an exception.
SilverStripe (or the core, Sapphire) offers a good approach to this, something like:
RewriteEngine On
RewriteCond %{REQUEST_URI} !(\.css)|(\.js)|(\.swf)$ [NC]
RewriteCond %{REQUEST_URI} .+
RewriteRule ^([^\.]+) /?post=$1 [L,R=301]
This requires the URI not to be empty, not to be JS, CSS or SWF, and redirects back to your root directory:
http://localhost/this-is-a-post.php
http://localhost/?post=this-is-a-post
If you don't want a redirection, but the processing, remove the redirection rule R=301