For instance I have a file php, index.php with content as below:
<ul>
<li>Menu</li>
<li>How it work</li>
</ul>
And I writed .htaccess as below:
RewriteEngine On
RewriteRule ^menu/?$ menu.php
RewriteRule ^how-it-work/?$ howitwork.php
But if I type localhost/menu or localhost/how-it-work it ok, But I want to see link under Menu and How it work also be writed to /menu and /how-it-work, currently it still menu.php and howitwork.php
Another issue, if I have file product.php?action=view&id=123, how could I use htaccess to change it to this localhost/product/123-name-of-topic/
I code and tested on localhost before make it live.
Thanks!
Sorry i cant understand your question first of all,
the final issue could be solved by using a post method in your form instead of get,
<form action="home.php" method="post">
....
....
</form>
Hope this helps.
If I understood right, here is an example:
MODIFIED
RewriteEngine On
RewriteCond %{REQUEST_URI} ^.*howitwork.*$
RewriteRule .* http://mydomain.com/how-it-work [L,R=301]
RewriteCond %{REQUEST_URI} ^.*menu.*$
RewriteRule .* http://mydomain.com/menu [L,R=301]
Related
I'm trying to use React to create a SPA, but I'm running into problem when trying to reload the page.
Before I continue, I must say I already read these questions this and this. I manageg to made it work, but only for the first url.
For example, I have a blog page containing all the posts, accessed via this url mysite.com/blog. This one works fine, if I refresh the page, everything reloads again.
However, when I try to access a single post using a dynamic url, then the page doesn't work. For example, I have this router setup:
// Definiton
<Route path="/post/:url" component={Post} />
// Link
<NavLink to={"post/" + post.url}>...</NavLink>
// Url on the browser
mysite.com/post/this-is-my-first-post
In this case, it's not working. This is my .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
After looking more at the problem, I noticed it's trying to load the main files from a different location. For example, when I'm on the page mysite.com/blog it's loading the .css and .js files from mysite.com.
But when I'm the page mysite.com/post/this-is-my-first-post and I refresh the page, it's trying to load the .css and .js files from the directory mysite.com/blog.
I did what Stuffix told in the answe, to check the url definition and also the config at my apache, but everything is enabled and working, just like the answer says.
Well, after looking at some other projects I have using Angular, I noticed one thing, and it was easier than I tought.
Just had to add the tag base on the head of my index.html.
<base href="/" />
This htaccess worked for me with react and angular
<IfModule mod_rewrite.c>
RewriteEngine on
# -- REDIRECTION to https (optional):
# If you need this, uncomment the next two commands
# RewriteCond %{HTTPS} !on
# RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
# --
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) index.html [NC,L]
</IfModule>
In your <Route />, you're declaring the post route is /post/this-is-my-first-post which is correct.
But in your <NavLink />, you're pointing towards /blog/post/this-is-my-first-post since you've missed a slash.
<NavLink to={"post/" + post.url}>...</NavLink>
| here
Thus leading to a 404.
If this doesn't help, your snippet looks fine so the problem might be on what does post.url returns.
Also, your .htaccess looks fine so I would say you might have missed something in your Apache config like AllowOverride all. See this answer.
I need to rewrite only 1 specific URL
from
http://www.domainname.com/index.php?route=payment/axis/callback
to
http://www.domainname.com/payment/axis/callback
I tried these two from stack overflow, I don't know why its not working
1st one :
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?route=payment/axis/callback [NC,L]
2nd one :
RewriteRule ^index.php?route=payment/axis/callback payment/axis/callback [L]
Try this:
4) Rewriting yoursite.com/user.php?username=xyz to yoursite.com/xyz
Have you checked zorpia.com.If you type http://zorpia.com/roshanbh233 in browser you can see my profile over there. If you want to do the same kind of redirection i.e http://yoursite.com/xyz to http://yoursite.com/user.php?username=xyz then you can add the following code to the .htaccess file.
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?username=$1
See the full page here.
Hope it helps!
I wouldn't use .htaccess with RewriteRule, since there are often problems with it. A simple workaround (with PHP redirect):
<?php
if($_GET['route'] == 'payment/axis/callback') {
header("Location: http://www.domainname.com/payment/axis/callback");
}
?>
You can either use h0ch5tr4355's workaround or you can try this:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^route=payment/axis/callback$
RewriteCond %{SCRIPT_FILENAME} index.php
RewriteRule (.*) /payment/axis/callback [NC,QSD]
If you instead of a rewrite would like it to redirect to the new url you can add R=301 to the flags of the RewriteRule.
Ok, im pretty new at this and I would really appreciate some help, thanks!
How can i rewrite this in .htaccess correctly?
So I have a query string in my url:
/?url=contact
All i want to do is remove the query string
/contact
Help? I scoured google and I'm learning the syntax right now, but the fact remains..I dont know how to do it just yet. Thanks to all
This was my solution:
RewriteRule ^(.*)$ index.php?url=$1 [L,QSA]
Try this:
RewriteEngine On
RewriteRule ^(.*)$ /index.php?url=$1 [L]
To a user on your site, they will see and navigate to this:
http://example.com/contact
But the real page would be something like this:
http://example.com/index.php?url=contact
This bit, [L], tells the server that this is the last line of the rewrite rule and to stop.
RewriteCond %{QUERY_STRING} url=(.*)
RewriteRule index.html %1
(or whatever if it's not index.html, index.php, whatever)
You need to capture the query string, which is not looked at by RewriteRule normally, and use the %1 back reference, not $1 as you would in a capture in a RewriteRule
Before: https://example.com/index.php?user=robert
RewriteEngine On
RewriteRule ^user/([^/]+)?$ index.php?user=$1 [L,QSA]
After: https://example.com/user/robert
I know this must have been answered on here before so I apologize in advance, but despite my numerous searches - I couldn't find a suitable answer.
I have an url, for instance: www.domain.com/blog/username which I'd like to redirect to www.domain.com/users/username
Another example:
www.domain.com/blog/joe-blogs becomes www.domain.com/users/joe-blogs
www.domain.com/blog/bill jones becomes www.domain.com/users/bill jones
www.domain.com/blog/adam becomes www.domain.com/users/adam
I've tried:
Rewriterule ^blog/(.+)$ ./users/$1
But it's not quite right and results in a 404.
I also want www.domain.com/blog to redirect to www.domain.com/users
I think you're pretty close. Change your rule to:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
Rewriterule ^forum/blog/(.+?)/?$ /users/$1 [L,NC,R=301]
With .htaccess files, you can do mod_rewrite which lets you do a bait and switch with webpages and also you can set up custom error documents. you can do a plain redirect by using a simple call to header() in PHP. place this on the top of orig. weppage(s) and set the target webpage:
<?php header('Location:http://www.somesite.com/users/username'); ?>
Make use of RedirectPermanent
RedirectPermanent /blog/username /users/username
If the above doesn't work..
RewriteEngine On
RewriteRule /blog/username /users/username [R=302]
RewriteRule /blog /users [R=302]
I am having an issue with the KO3 core inserting index.php into my URL's when I use redirect
Request::instance()->redirect('something'); or $paginationStuffHere->render().
The result of either of these is http://www.something.com/index.php/something
This is not an issue when I use full URL's for the redirects instead of relatives such as Request::instance()->redirect('http://www.something.com/something'); but there is not really a way to do this with the pagination functions... that I have found, so I really need to find where it is adding this index.php
This does not occur when I use View::factory('something/something')->render(); which is the only thing I have been able to find people having similar problems with
The base URL is set to '/' in bootstrap.php
My .htaccess looks like this
RewriteEngine On
RewriteBase /
RewriteRule ^(application|modules|system) -[F,L]
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule .* index.php/$0 [PT,L]
Thanks in advance for any suggestions.
Find Kohana::init() in your bootstrap.php and set index_file to FALSE in that array