url rewrite `/abc/products-` to `/def/products-` [closed] - apache

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have many url links in /abc/ sub-directory, like
http://www.domain.com/abc/products-12345
http://www.domain.com/abc/products-23456
http://www.domain.com/abc/products-34567
http://www.domain.com/abc/new-items
Now I want to url rewrite /abc/products- to /def/products-
http://www.domain.com/def/products-12345
http://www.domain.com/def/products-23456
http://www.domain.com/def/products-34567
http://www.domain.com/abc/new-items
My code in .htaccess, but nothing changed. How to rewrite in this case? Thanks.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^abc/products-(.*)$ /def/products-$1 [L,R=301]
</IfModule>

As you can test on this simulator the rules should work.
The most probable problem you are facing should be:
The global configuration does not allow for .htaccess overwrite
.htaccess is not readable for apache user
You have no mod_rewrite active on this apache server, thus no trigger to <IfModule> directive.
Best troubleshooting option would be trying a redirection of all page to a static page. If this does not work, look for a configuration problem.

Related

Change Link href from .htaccess [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 12 months ago.
Improve this question
I want to change url used in href from .htaccess. As I am working in a existing project so I don't want to change the href from 46 files. Is there any way? For instance the code below is in the html file.
<link href="http://localhost/example.com/UK/styles/style.css">
I want to change it to http://localhost/example.com/styles/style.css from .htaccess
Here, my absolute domain is http://localhost/example.com
And my .htaccess is in the document root
.htaccess doesn't actually "change url used in href", but it allows you to internally rewrite a request from /example.com/UK/styles/styles.css to /example.com/styles/styles.css. The user still sees /UK in the URL, the URL is unchanged, but the file that receives the request is.
For example, at the top of the .htaccess file in the "document root". (ie. at http://localhost/.htaccess) you can do something like the following:
RewriteEngine On
RewriteRule ^(example\.com)/UK/(styles/style.css)$ $1/$2 [L]
For a more general "any URL" solution:
RewriteRule ^(example\.com)/UK/(.*) $1/$2 [L]
$1 and $2 are backreferences to the captured subpatterns in the preceding RewriteRule pattern.
Reference:
https://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule

Convert NGINX rewrite rules to Apache htaccess [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I have a client who is moving away from an NGINX webserver to Apache. Everything is simple nothing complicated however since I'm an NGINX kinda guy I forgot how to convert the NGINX rewrite rules onto apache ones.
For example, these are the NGINX rewrites
rewrite ^/Tower-Topics-Calendar/?$ https://$host/events/ permanent;
How would I convert something like that onto .htaccess to use with Apache?
rewrite ^/Tower-Topics-Calendar/?$ https://$host/events/ permanent;
This looks like an external 301 redirect from /Tower-Topics-Calendar (with and without a trailing slash) to https://<host>/events/ - where <host> is the same hostname from the request and you specifically state the HTTPS protocol in the target.
In .htaccess you can achieve this using mod_rewrite. For example:
RewriteEngine On
RewriteRule ^Tower-Topics-Calendar/?$ https://%{HTTP_HOST}/events/ [R=301,L]
Note the absence of the slash prefix in the RewriteRule pattern.
However, if you don't specifically need to include the HTTPS scheme (ie. this is already canonicalised) then you can use a single mod_alias RedirectMatch directive instead. For example:
RedirectMatch 301 ^Tower-Topics-Calendar/?$ /events/
OR, to include the HTTPS protocol, you need to hardcode the hostname:
RedirectMatch 301 ^Tower-Topics-Calendar/?$ https://example.com/events/

How to make a webpage without .html in your URL [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Like the title says I want to visit my webpage without typing .html after the webadres.
So for example I have to type this at the moment: www.webadres.com/webpage.html
Now I want to change that into www.webadres.com/webpage
I've already tried some things like deleting the .html extension on the end of my file but that (of course) doesn't work.
I see I missed something:
I don't really understand it but I got a folder (called "cgi-bin") with a .htacces file.
In the .htacces file is the following text:
Options -Indexes +ExecCGI AddHandler cgi-script .cgi .pl
I want a webpage like this
www.example.com/webpage
Instead of
www.example.com/webpage.html
I didn't know about all the server side technologies but now it seems I have Apache.
If it didn't worked out you could also check out these:
How to remove .html from URL
ReWrite rule to add .html extension
create a htaccess file which has the name of .htaccess, then place the following code
RewriteEngine on
RewriteRule ^yourPage$ yourPage.html [NC,L]

Error 500 with .htaccess edits but mod_rewrite is loaded [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
as of title, I'm having problems with my .htaccess file, everything should be set fine, but has I write something as basic as
RewriteEngine on
it starts giving me that nice 500 Internal Server Error. I'm hosting on localhost on an Apache server (UNIX)
Obviously I triple checked that everything is set fine, and top of all that mod_rewrite is loaded.
Thanks for your precious help!
If the error occurs for every single type of instruction you put in the file (that is, caching, FilesMatch, ErrorDocument, etc), there are two possible options that I can think of right now:
The encoding of your .htaccess file is not compatible with the server you're running. Try converting it to ANSI, and then try again (Apache does not support Byte Order Marks, so you'd need to save it to ANSI, or UTF-8, without the BOM). If that does not work:
AllowOverride is not set correctly, or not at all. If you have access to the Virtual Host/Directory configuration, you'll need to enable it by adding the line AllowOverride All in the <Directory> container.
When you try to remove the code RewriteEngine on and the URL remapping or the URL redirecting is still functioning well, then you do not have to put that code in your .htaccess file, for your HTTP server was already configured that the rewrite engine is on. But if you've tried to remove it and the rewriting or the redirecting stop, then you must include all your .htaccess codes in your question. Then if it's empty, then why you need to turn the RewriteEngine on if you're not going to apply even a single RewriteRule?
Have you ever tried this:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^notexist.html$ /index.html
And try to visit yourdomain.com/notexist.html if it's URL remapping into /index.html.

Redirect ALL requests under a domain to static page [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 13 years ago.
Improve this question
I am trying to redirect ALL requests for mydomain.com whether they are something like:
http://www.mydomain.com
http://mydomain.com
http://mydomain.com/photos
http://mydomain.com/index.php?id=672
to be redirected to
http://mydomain.com/index.html
As long as it has mydomain.com in it, they should see this page - its a we'll be back soon message.
Should I do it in .htaccess or conf? How?
I actually ended up finding the answer on ServerFault:
https://serverfault.com/questions/32513/url-redirect-to-another-page-on-the-same-site
"This example will 302 redirect all URLs to "/underconstruction.html":
RewriteEngine On
RewriteCond %{REQUEST_URI} !=/underconstruction.html
RewriteRule ^ /underconstruction.html [R=302]
(which translates as "If URI is not /underconstruction.html, redirect to /underconstruction.html")" - Tommeh