So I duplicated and installed an existing Wordpress Site on my Server and linked it to a subdomain:
sub.domain.com
After I was finished with the work I put it back on to the main Domain but the problem now is that every image on the site has the URL sub.domain.com/wp-content/... instead of domain.com/wp-content/... and doesnt get displayed.
Is it somehow possible to rewrite the URL using htaccess so the images get displayed or do I need to change every single URL on every Image via mySQL?
My htaccess approach would be like:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,NC,QSA]
If this doesnt work, how can I do it in mySQL? Like every link in the database automated overwrite
I would not use a rewrite for this. That is pretty messy. If your links are stored in the DB then just update it in mysql. You can do it with one easy replace command.
UPDATE your_table
SET your_field = REPLACE(your_field, 'http://sub.domain.com', 'http://www.domain.com')
WHERE your_field LIKE '%http://sub.domain.com%'
Always back up your DB before doing any special updates like this.
Related
Is there a way in Apache to make URLs only accessible during certain times/inaccessible after a specific point in time? I am looking for a solution using Apache only; I know it can be done manually or by scheduling a cron job to remove the file.
Example:
I have a web page accessible via http://example.com/aboutthisproject.html which I want to send to clients via email. I want that link to expire and the page not to be accessible after, let's say, one week. So when someone who has the link types in their browser http://example.com/aboutthisproject.html they should get a 404 error.
What options do I have besides manually moving or renaming the file? I want to be able to set an expiring date for that page and forget about having to keep in mind to go back and rename or move the file.
Have you look into apache mod_rewrite with server variables date+time? Using Rewrite condition based on date+time you could do a 404.
see https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html
example:
RewriteEngine On
# between 03 am and 4am
RewriteCond %{TIME_HOUR} >02
RewriteCond %{TIME_HOUR} <05
RewriteRule ^index\.html$ /morning/index.html
I have the following issue: we have an internal documentation system which generates help files as HTML. The software that generates them was recently upgraded and now there is a naming issue between capitalized and non capitalized folders.
Old URLs:
https://documentation.example.com/de/101/Skins/Default/Stylesheets/Components/Tablet.css
New URLs:
https://documentation.example.com/de/101/skins/default/stylesheets/components/tablet.css
We have different folders that are affected, so the URLs could look like this (there are many variations):
https://documentation.example.com/en/103/Skins/Default/Stylesheets/Components/Tablet.css
https://documentation.example.com/de/456/Skins/Default/Stylesheets/Components/Tablet.css
https://documentation.example.com/en/324/Skins/Default/Stylesheets/Components/Tablet.css
I would like to be able to take the requested URL, look for this string: "/Skins/Default/Stylesheets/Components/Tablet.css" change it to lowercase and then send the user on to the new changed URL.
Some of the solutions I have found require access to vhosts files which I don't. I am also unable to upload a PHP file or something like that.
Are there any solutions to my problem that could be done with the htaccess file alone? If yes how?
You need to define a rewrite map in your server/vhost config file where the css is hosted.
RewriteMap lc int:tolower
Then in your htaccess file, you can create a rule like:
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule ^(.*)$ ${lc:$1} [L,NC]
Let me know if you need anymore help. This htaccess rule will cause every url to be converted to lowercase. This is a generic htaccess you could make it more refined to search specifically for the URL you need.
I want to do URL rewrite in html pages.
Any help for that. every one knows about url rewrite but I found all article for pp, asp.net, classic asp. so please any one knows how to do url rewrite in html.
like wise I want to rewrite from
http://www.xyz.com/aboutus.html to http://www.xyz.com/About-us
Any help will appreciated.
Thank you.
I'm not normally huge on working with RewriteEngine, or .htacess, but according to this blog entry, you can use the following code to hide file extensions:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
Just paste that in your .htaccess file, and put the changes to the server (upload the new .htaccess using an HTTP client). If your .htaccess already has RewriteEngine on, you should skip the first line.
If you want to change the URL from xyz.com/aboutus.html to xyz.com/About-Us, you also have to change the name of the file or folder aboutus to About-Us. Another possible solution would involve just having an index.html file in a folder named About-Us, which would make the server load that file automatically once a user accesses xyz.com/About-Us, and wouldn't display the filename.
To rewrite urls you need to configure the webserver to do that (for example in apache with .htaccess.
But if you want to do that without use server configuration, a bad solution exists: make a folder with the name of the url and put the html into that with the name index.php. For example about-us.html > about-us/index.html and in links put the url about-us. But is a bad solution.
I'm using a proxy-like short domain in conjunction with my site. The short domain is hrci.me and the long domain is reachchallenges.infectionist.com. hrci.me uses mod_rewrite and has a rule that pretty much does a simple redirect from hrci.me to reachchallenges.infectionist.com, so for example:
hrci.me/x/y.php
would redirect to
reachchallenges.infectionist.com/x/y.php
Simple as can be. On the main site I have more rules that further rewrite the URL, prettifying it. One example is a script on my site, challenges.php, which accepts a single parameter, chid, which is the challenge ID linked to more information in the database. Passed as a parameterized script it would look like this: /challenge.php?chid=123, but after it's rewritten it looks like this: /challenge/123/Challenge+Title/, where Challenge+Title is the actual title of the item from the database. There's also a different way you can call the same page, like this: /ch123, so in essence you can access the page 3 different ways:
1. /challenge.php?chid=123
2. /challenge/123/Challenge+Title/
3. /ch123
This actually works perfectly, the issue that I have is that I want the URLs that are redirected from hrci.me to first be rewritten to look like #2 above, so the user would click hrci.me/ch123 and the htaccess file would read the database, get the title for challenge id 123, rewrite the url to /challenge/123/Challenge+Title/ and then redirect it to reachchallenges.infectionist.com. Is something like this possible? Is it possible to read from a MySQL database using htaccess in this way?
UPDATE:
I added this to my httpd.conf file:
DBDriver mysql
DBDParams "host=*****,user=*****,pass=*****,dbname=*****"
RewriteMap hrci "dbd:SELECT title FROM challenges WHERE id = %s"
RewriteLog "/home/halo2freeek/rewrite.log"
RewriteLogLevel 3
Then added a RewriteRule to one of my subdomains that I don't really use (to test it):
RewriteEngine On
RewriteRule ^ch([0-9]{1,4})(/)?$ http://reachchallenges.infectionist.com/challenge/$1/${hrci:$1} [R=301,L]
When I visit this path on the subdomain:
/ch232
It should redirect to:
http://reachchallenges.infectionist.com/challenge/232/Challenge+Title
But instead it redirects to:
http://reachchallenges.infectionist.com/challenge/232/
Without the title. Am I doing something wrong? Do I have to specify RewriteEngine On in the httpd.conf file?
UPDATE 2: Ok, so I added the RewriteEngine On line and saved, when I tried to restart Apache I got this error:
RewriteMap: file for map hrci not found:/dh/apache2/apache2-ps54462/dbd:SELECT title FROM challenges WHERE id = %s
It looks like it's completely ignoring the dbd part and trying to read the whole thing as a file name. Now I really don't know what I'm doing wrong.
With RewriteMap everything is possible:
RewriteMap examplemap prg:/path/to/file.php
RewriteRule (.*) ${examplemap:$1}
You can use mod_dbd as well:
DBDriver mysql
DBDParams "host=localhost,user=db_user,pass=password,dbname=db"
RewriteMap myquery "dbd:select new_url from rewrite where old_url = %s"
RewriteRule (.*) ${myquery:$1}
So I'm going straight to business. Both tested and confirmed on XAMPP (Windows 7 32-Bit) and MAMP (OS X Snow Leopard), both newest versions. I have the following site structure:
/op/.htaccess
/op/index.php
/op/profile.php
The paths are the absolute paths from Apache document root.
My .htaccess file looks like this:
RewriteEngine on
RewriteRule ^[a-zA-Z0-9]+$ profile.php?alias=$1
When I request the site via http://localhost:8888/op/ the document index.php is opened. That's okay. When I request via http://localhost:8888/op/example the document profile.php is opened, that's also fine. And there is set up a GET parameter with the name alias just like desired. But it's value is simply empty! Like this:
http://localhost:8888/op/profile.php?alias=
So I just want to pass on the last part of the url as a GET variable that it looks like this for the server:
http://localhost:8888/op/profile.php?alias=example
I am slowly getting desperate. I am fighting with this since two and a half hours now. Either it is a wrong server configuration or a real silly mistake. I guess it's the regular expression, but I just don't get it.
It's a regex thing, your htaccess should look like this:
RewriteEngine on
RewriteRule ^([a-zA-Z0-9]+)$ profile.php?alias=$1
The $1 at the end of the string matches the first sub-pattern, but you didn't indicate any sub-pattern. The first set of parenthesis is the first sub-pattern.
Additionally, you may wish to indicate a RewriteBase
RewriteEngine on
RewriteBase /
RewriteRule ^([a-zA-Z0-9]+)$ profile.php?alias=$1